File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -43,11 +43,17 @@ class Cache {
43
43
}
44
44
45
45
generateRedisKey ( request ) {
46
- return `${ this . redisKeyPrefix } _${ md5 ( request . body ) } `
46
+ try {
47
+ const bodyData = request . body || request . res
48
+ return `${ this . redisKeyPrefix } _${ md5 ( bodyData ) } `
49
+ } catch ( error ) {
50
+ return null
51
+ }
47
52
}
48
53
49
54
async getCache ( request ) {
50
- if ( this . enabled ) {
55
+ const cacheKey = this . generateRedisKey ( request )
56
+ if ( this . enabled && cacheKey ) {
51
57
return new Promise ( ( resolve , reject ) => {
52
58
this . redisClient . get ( this . generateRedisKey ( request ) , ( error , value ) => {
53
59
if ( error ) return reject ( error )
@@ -59,7 +65,8 @@ class Cache {
59
65
}
60
66
61
67
async cacheResult ( request , result ) {
62
- if ( this . enabled ) {
68
+ const cacheKey = this . generateRedisKey ( request )
69
+ if ( this . enabled && cacheKey ) {
63
70
await this . redisClient . setex ( this . generateRedisKey ( request ) , parseInt ( this . timeout ) , JSON . stringify ( result ) )
64
71
}
65
72
}
You can’t perform that action at this time.
0 commit comments