forked from jeromeetienne/MicroCache.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicrocache.js
More file actions
29 lines (27 loc) · 745 Bytes
/
microcache.js
File metadata and controls
29 lines (27 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Micro Cache
* - a micro library to handle a inmemory cache
* - works in node and browser.
*
* @tags inmemory, keyvalue, cache, node, browser
*/
var MicroCache = function(){
var _values = {};
return {
get : function(key){ return _values[key]; },
contains: function(key){ return key in _values; },
remove : function(key){ delete _values[key]; },
set : function(key, value){ _values[key] = value;},
values : function(){ return _values; },
getSet : function(key, value){
if( !this.contains(key) ){
this.set(key, typeof value == 'function' ? value() : value )
}
return this.get(key);
}
}
}
// export in common js
if( typeof module !== "undefined" && ('exports' in module)){
module.exports = MicroCache;
}