@@ -36,7 +36,9 @@ function redisCacheModule(config){
36
36
self . backgroundRefreshIntervalCheck = ( typeof config . backgroundRefreshIntervalCheck === 'boolean' ) ? config . backgroundRefreshIntervalCheck : true ;
37
37
self . backgroundRefreshInterval = config . backgroundRefreshInterval || 60000 ;
38
38
self . backgroundRefreshMinTtl = config . backgroundRefreshMinTtl || 70000 ;
39
+ self . JSON = config . JSON || Object . create ( JSON ) ;
39
40
self . logJsonParseFailures = config . logJsonParseFailures || false ;
41
+
40
42
var refreshKeys = { } ;
41
43
var backgroundRefreshEnabled = false ;
42
44
@@ -134,7 +136,7 @@ function redisCacheModule(config){
134
136
log ( false , 'Attempting to get key:' , { key : cacheKey } ) ;
135
137
self . db . get ( cacheKey , function ( err , result ) {
136
138
try {
137
- result = JSON . parse ( result ) ;
139
+ result = self . JSON . parse ( result ) ;
138
140
} catch ( err ) {
139
141
if ( self . logJsonParseFailures ) {
140
142
log ( true , 'Error parsing JSON, err:' , err ) ;
@@ -163,7 +165,7 @@ function redisCacheModule(config){
163
165
for ( var i = 0 ; i < response . length ; i ++ ) {
164
166
if ( response [ i ] !== null ) {
165
167
try {
166
- response [ i ] = JSON . parse ( response [ i ] ) ;
168
+ response [ i ] = self . JSON . parse ( response [ i ] ) ;
167
169
} catch ( err ) {
168
170
if ( self . logJsonParseFailures ) {
169
171
log ( true , 'Error parsing JSON, err:' , err ) ;
@@ -201,7 +203,7 @@ function redisCacheModule(config){
201
203
var exp = ( expiration * 1000 ) + Date . now ( ) ;
202
204
if ( typeof value === 'object' ) {
203
205
try {
204
- value = JSON . stringify ( value ) ;
206
+ value = self . JSON . stringify ( value ) ;
205
207
} catch ( err ) {
206
208
if ( self . logJsonParseFailures ) {
207
209
log ( true , 'Error converting to JSON, err:' , err ) ;
@@ -252,7 +254,7 @@ function redisCacheModule(config){
252
254
value = value . cacheValue ;
253
255
}
254
256
try {
255
- value = JSON . stringify ( value ) ;
257
+ value = self . JSON . stringify ( value ) ;
256
258
} catch ( err ) {
257
259
if ( self . logJsonParseFailures ) {
258
260
log ( true , 'Error converting to JSON, err:' , err ) ;
@@ -342,13 +344,13 @@ function redisCacheModule(config){
342
344
if ( self . redisData ) {
343
345
if ( typeof self . redisData === 'string' ) {
344
346
self . db = redis . createClient ( self . redisData ,
345
- { 'no_ready_check' : true ,
347
+ { 'no_ready_check' : true ,
346
348
retry_strategy : retryStrategy } ) ;
347
349
} else {
348
350
self . db = redis . createClient ( self . redisData . port ,
349
- self . redisData . hostname , { 'no_ready_check' : true ,
351
+ self . redisData . hostname , { 'no_ready_check' : true ,
350
352
retry_strategy : retryStrategy } ) ;
351
-
353
+
352
354
// don't call redis auth method if no auth info passed
353
355
if ( self . redisData . auth ) {
354
356
self . db . auth ( self . redisData . auth ) ;
0 commit comments