forked from ptarjan/node-cache
/
test.js
38 lines (29 loc) · 840 Bytes
/
test.js
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
30
31
32
33
34
35
36
37
38
var cache = require('./index')
sys = require('sys')
;
cache.debug(false);
sys.puts('null == '+cache.get('a'));
sys.puts('0 == '+cache.size());
cache.put('a', 'b', 3000);
sys.puts('1 == '+cache.size());
sys.puts('b == '+cache.get('a'));
var complicated = ['a',{'b':'c','d':['e',3]},'@'];
cache.put(complicated, true);
sys.puts('true == '+cache.get(complicated));
cache.del(complicated);
sys.puts('null == '+cache.get(complicated));
sys.puts('1 == '+cache.size());
cache.put(0, 0);
sys.puts('2 == '+cache.size());
cache.del(0);
setTimeout(function() {
sys.puts('b == '+cache.get('a'));
}, 2000);
setTimeout(function() {
sys.puts('null == '+cache.get('a'));
sys.puts('0 == '+cache.size());
}, 4000);
setTimeout(function() {
sys.puts('Cache hits: ' + cache.hits());
sys.puts('Cache misses: ' + cache.misses());
}, 5000);