🌟 memory-cache의 README.md에 실시간 사용 차트를 표시하려면 아래 코드를 복사하세요.
## Usage Trend
[](https://npm-compare.com/memory-cache#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
🌟 memory-cache의 README.md에 GitHub Stars 트렌드 차트를 표시하려면 아래 코드를 복사하세요.
## GitHub Stars Trend
[](https://npm-compare.com/memory-cache)
통계 세부사항
패키지
다운로드
Stars
크기
Issues
발행일
라이선스
memory-cache
510,071
1,602
-
32
8年前
BSD-2-Clause
인기 비교
memory-cache
memory-cache의 README
memory-cache
A simple in-memory cache for node.js
Installation
npm install memory-cache --save
Usage
var cache = require('memory-cache');
// now just use the cache
cache.put('foo', 'bar');
console.log(cache.get('foo'));
// that wasn't too interesting, here's the good part
cache.put('houdini', 'disappear', 100, function(key, value) {
console.log(key + ' did ' + value);
}); // Time in ms
console.log('Houdini will now ' + cache.get('houdini'));
setTimeout(function() {
console.log('Houdini is ' + cache.get('houdini'));
}, 200);
// create new cache instance
var newCache = new cache.Cache();
newCache.put('foo', 'newbaz');
setTimeout(function() {
console.log('foo in old cache is ' + cache.get('foo'));
console.log('foo in new cache is ' + newCache.get('foo'));
}, 200);
which should print
bar
Houdini will now disappear
houdini did disappear
Houdini is null
foo in old cache is baz
foo in new cache is newbaz
API
put = function(key, value, time, timeoutCallback)
Simply stores a value
If time isn't passed in, it is stored forever
Will actually remove the value in the specified time in ms (via setTimeout)
timeoutCallback is optional function fired after entry has expired with key and value passed (function(key, value) {})
Returns the cached value
get = function(key)
Retrieves a value for a given key
If value isn't cached, returns null
del = function(key)
Deletes a key, returns a boolean specifying whether or not the key was deleted
clear = function()
Deletes all keys
size = function()
Returns the current number of entries in the cache
memsize = function()
Returns the number of entries taking up space in the cache
Will usually == size() unless a setTimeout removal went wrong
debug = function(bool)
Turns on or off debugging
hits = function()
Returns the number of cache hits (only monitored in debug mode)
misses = function()
Returns the number of cache misses (only monitored in debug mode)
keys = function()
Returns all the cache keys
exportJson = function()
Returns a JSON string representing all the cache data