
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
cachify-wrapper
Advanced tools
Wraps a function with a caching layer
Wraps a function with a caching layer
fn
function callback-last
style functionstorage
Storage<K, RecordPacked<V>> cache storage (optional, default InMemoryStorageCb
)options
Options (optional, default {}
)hasher
Function creates key for KV-storage from fn
arguments (optional, default JSON.stringify
)const wrapper = require('cachify-wrapper').default;
class Storage {
constructor() {
this.data = new Map();
}
get = (key, cb) => cb(null, this.data.get(key))
set = (key, value, ttl, cb) => {
this.data.set(key, value);
if (ttl > 0) setTimeout(() => this.data.delete(key), ttl);
cb(null, true);
}
del = (key, cb) => cb(null, this.data.delete(key))
}
const storage = new Storage();
let count = 0;
const inc = (a, cb) => cb(null, count += a);
const cached = wrapper(inc, storage, {expire: 100});
setTimeout(() => cached(1, (_error, payload) => console.info(payload)), 0); // Invokes request
setTimeout(() => cached(1, (_error, payload) => console.info(payload)), 100); // Takes cached result
setTimeout(() => cached(1, (_error, payload) => console.info(payload)), 200); // Invokes second request
cached.set(2, 'manual value', 1000, () =>
cached.get(2, (_, result) => {
console.info(result);
cached.del(2, () =>
cached.get(2, (_, result) => console.info(result)))
}));
Returns function
Wraps a function with a caching layer
fn
functionstorage
Storage<K, RecordPacked<V>>?options
Options?hasher
Function?const wrapperPromise = require('cachify-wrapper').promise;
let count = 0;
const inc = async(a) => count += a;
const cached = wrapperPromise(inc, storage, {expire: 1000});
const p1 = cached(1).then((payload) => console.info(payload)); // Invokes request
const p2 = p1.then(() => cached(1).then((payload) => console.info(payload))); // Takes cached result
Returns function (...any): Promise<any>
Type: Object
storage
Object?
storage.timeout
number? max storage response time before considering it as failed, and invoking fn
source
Object?
source.timeout
number? max fn
response time before considering it as failedexpire
number? time to consider cached data expired [in milliseconds]
spread
number? expire time spread (prevents simultaneous deletions saved items from storage)
lock
number? lock timeout (prevents simultaneous concurrent invoke of fn
at initial period)
stale
number? additional ttl for stale data
ttl
number? forced ttl (TimeToLive) for data (useful if storage is using from multiply services with different expire)
retries
number? number of storage requests passes before fn
call
error
number? ttl for erroneous state cache (prevents frequent call of fn
)
verbose
number? verbosity flag
Extends Error
no cache error
storage interface
key
Kcb
CB<V>key
Kcb
CB<boolean>Type: Object
key
Kcb
CB<V>key
Kcb
CB<boolean>Extends InMemoryStorage
key
Kttl
numberReturns Iterable<KRecordTuple<K, V>>
dump
Iterable<KRecordTuple<K, V>>Type: Object
source
Iterable<KRecordTuple<K, V>>?key
Kkey
Kvalue
Vkey
Kkey
Kkey
Kttl
numberFAQs
Wraps a function with a caching layer
The npm package cachify-wrapper receives a total of 17 weekly downloads. As such, cachify-wrapper popularity was classified as not popular.
We found that cachify-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.