@@ -10,7 +10,8 @@ var redis_cache = cache_manager.caching({store: redis_store, db: 0, ttl: 100});
10
10
var ttl = 60 ;
11
11
12
12
console . log ( "set/get/del example:" ) ;
13
- redis_cache . set ( 'foo' , 'bar' , ttl , function ( err ) {
13
+
14
+ redis_cache . set ( 'foo' , 'bar' , { ttl : ttl } , function ( err ) {
14
15
if ( err ) { throw err ; }
15
16
16
17
redis_cache . get ( 'foo' , function ( err , result ) {
@@ -23,6 +24,34 @@ redis_cache.set('foo', 'bar', ttl, function(err) {
23
24
} ) ;
24
25
} ) ;
25
26
27
+ // TTL defaults to what we passed into the caching function (100)
28
+ redis_cache . set ( 'foo-no-ttl' , 'bar-no-ttl' , function ( err ) {
29
+ if ( err ) { throw err ; }
30
+
31
+ redis_cache . get ( 'foo-no-ttl' , function ( err , result ) {
32
+ if ( err ) { throw err ; }
33
+ console . log ( "result fetched from cache: " + result ) ;
34
+ // >> 'bar'
35
+ redis_cache . del ( 'foo-no-ttl' , function ( err ) {
36
+ if ( err ) { throw err ; }
37
+ } ) ;
38
+ } ) ;
39
+ } ) ;
40
+
41
+ // Calls Redis 'set' instead of 'setex'
42
+ redis_cache . set ( 'foo-zero-ttl' , 'bar-zero-ttl' , { ttl : 0 } , function ( err ) {
43
+ if ( err ) { throw err ; }
44
+
45
+ redis_cache . get ( 'foo-zero-ttl' , function ( err , result ) {
46
+ if ( err ) { throw err ; }
47
+ console . log ( "result fetched from cache: " + result ) ;
48
+ // >> 'bar'
49
+ redis_cache . del ( 'foo-zero-ttl' , function ( err ) {
50
+ if ( err ) { throw err ; }
51
+ } ) ;
52
+ } ) ;
53
+ } ) ;
54
+
26
55
var user_id = 123 ;
27
56
28
57
function create_key ( id ) {
@@ -40,7 +69,7 @@ function get_user_from_cache(id, cb) {
40
69
var key = create_key ( id ) ;
41
70
redis_cache . wrap ( key , function ( cache_cb ) {
42
71
get_user ( user_id , cache_cb ) ;
43
- } , ttl , cb ) ;
72
+ } , { ttl : ttl } , cb ) ;
44
73
}
45
74
46
75
get_user_from_cache ( user_id , function ( err , user ) {
0 commit comments