Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
popular-cache
Advanced tools
An in-memory LRU cache with easy statistics and smart proxy mode.
npm install popular-cache --save
var pcache = require('popular-cache');
cache = pcache({
maxSize: 500,
maxAge: 1000 * 60 * 60 // in millisecond
}),
smallCache = pcache(50); // or simply sets max size
// basic usage
cache.set("key", "value")
cache.get("key")
cache.del("key") // delete key
cache.size() // get size
cache.reset() // resets cache
cache.hits() // get total hits
cache.misses() // get total misses
// print the most popular keys and the number of hits
cache.popular(function(key, value, hits){
console.log(key + ': ' + hits);
}, 5);
// print the most recently used keys and the number of hits
cache.recent(function(key, value, hits){
console.log(key + ': ' + hits);
}, 10);
Proxy mode is as simple as telling popular-cache what you want and then you just get and get. Cache misses and concurrent requests are handled automatically.
// some time consuming process like HTTP request
var httpRequest = function(key, callback){
setTimeout(function(){
if(key=='popular-cache') callback('I am popular-cache');
else callback('others');
}, 1000);
}
var cache = pcache(50).proxy(httpRequest);
cache.get('popular-cache', function(value){
console.log(value); // I am popular-cache
});
cache.get('another key', function(value){
console.log(value); // others
});
The only difference in proxy mode is how the value is returned.
set(key, value)
get(key) (Normal Mode)
get(key, function(value)) (Proxy Mode)
get(key)
except how the value is returned. The callback function(value)
is required in proxy mode to receive the value.del(key)
size()
reset()
hits()
misses()
recent(function(key, value, hits), [limit])
key
: the key of the entry.value
: the value of the entry.hits
: the number of hits of the entry.limit
: optional, the maximum number of iterations.popular(function(key, value, hits), [limit])
key
: the key of the entry.value
: the value of the entry.hits
: the number of hits of the entry.limit
: optional, the maximum number of iterations.FAQs
An in-memory LRU cache with built-in statistics and proxy mode.
The npm package popular-cache receives a total of 1 weekly downloads. As such, popular-cache popularity was classified as not popular.
We found that popular-cache 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.