Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

diogenes-utils

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diogenes-utils

Utilities for diogenes

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

Diogenes-utils

cacheService

A decorator to cache services. The decorator works for function returning synchronously or returning a promise. The cache is based on the service dependencies: if they don't change the result is not cached. If the decorated function throws an exception or returns a rejected promise, this is not cached.

The decorator uses a LRU cache algorithm to decide whether to get rid of a cached value. It also supports a time-to-live for cached values. But you have to consider stale cache entries are not removed until the size of the cache exceeds the length. This allows to keep the running time of the algorithm constant (O(1)) for any operation.

const cacheService = require('diogenes-utils').cacheService
const cacheTTL = cacheService({ len: 1, ttl: 1 })
const cachedFunc = cacheTTL((d) => {
  return Promise.resolve(d.a + d.b)
})
  • len: is the number of items in the cache
  • ttl: is the time to live of cached items (in ms)

Keywords

plugins

FAQs

Package last updated on 23 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts