
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@criipto/cache
Advanced tools
Cache implementations for Node.js/TypeScript
All the cache implementations allow you to inject policy decision callbacks.
Policies help you define how the cache should behave when it is updating or hold stale data.
import {CacheUpdatePolicy, CachePendingPolicy} from '@criipto/cache';
CacheUpdatePolicy
CacheUpdatePolicy.UPDATE: Trigger update of value for cache keyCacheUpdatePolicy.DONT_UPDATE: No-op, keep current valueCachePendingPolicy
CachePendingPolicy.WAIT: Blocks the read while waiting for cache refresh to finishCachePendingPolicy.STALE: Return stale cache data while the cache updates
import {CacheUpdatePolicy, CachePendingPolicy, memoryCache} from '@criipto/cache';
const metadataCache = memoryCache({
updatePolicy: (url, {lastUpdatedAt}) => {
// Update metadata if data is more than an hour old
if (lastUpdatedAt.valueOf() < (Date.now() - 60 * 60 * 1000)) {
return CacheUpdatePolicy.UPDATE;
}
return CacheUpdatePolicy.DONT_UPDATE;
},
pendingPolicy: () => CachePendingPolicy.STALE,
refresh: async (url: URL) => {
return await fetch(url);
}
});
import {CacheUpdatePolicy, CachePendingPolicy, storedCache} from '@criipto/cache';
const metadataCache = storedCache({
updatePolicy: (url, {lastUpdatedAt}) => {
// Update metadata if data is more than an hour old
if (lastUpdatedAt.valueOf() < (Date.now() - 60 * 60 * 1000)) {
return CacheUpdatePolicy.UPDATE;
}
return CacheUpdatePolicy.DONT_UPDATE;
},
pendingPolicy: () => CachePendingPolicy.STALE,
refresh: async (url: URL) => {
const response = await fetch(url);
if (response.status !== 200) throw new Error('Not 200');
return response.json() as Promise<{metadata: string}>
},
storage: {
getItem: async (url) => {
return await fetchFromStorageImplementation(url);
},
setItem: async (url, data) => {
return await upsertInStorageImplementation(url, data);
}
}
});
FAQs
Cache implementations for Node.js/TypeScript
The npm package @criipto/cache receives a total of 87 weekly downloads. As such, @criipto/cache popularity was classified as not popular.
We found that @criipto/cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.