File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -155,7 +155,8 @@ module.exports = {
155155};
156156```
157157
158- You can also skip cahce hook by passing ` hook.params.$skipCacheHook = true `
158+ You can also skip cache hook by passing ` hook.params.$skipCacheHook = true `
159+ You can also disable redis-cache hooks and service by passing env. variable ` DISABLE_REDIS_CACHE=true `
159160
160161## TODO:
161162- TS definitions
Original file line number Diff line number Diff line change 22import redis from 'redis' ;
33import chalk from 'chalk' ;
44
5+ const { DISABLE_REDIS_CACHE } = process . env ;
6+
57export default ( options : any = { } ) => {
68 const errorLogger = options . errorLogger || console . error ;
79 const retryInterval = options . retryInterval || 5000 ;
810
11+ if ( DISABLE_REDIS_CACHE ) {
12+ return ( ) => { } ;
13+ }
14+
915 return function client ( ) {
1016 const app = this ;
1117 const config = app . get ( 'redis' ) || { } ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import chalk from 'chalk';
44import qs from 'qs' ;
55import async from 'async' ;
66
7+ const { DISABLE_REDIS_CACHE } = process . env ;
78const HTTP_OK = 200 ;
89const HTTP_NO_CONTENT = 204 ;
910const HTTP_SERVER_ERROR = 500 ;
@@ -29,6 +30,10 @@ function cacheKey(hook) {
2930
3031export default {
3132 before ( passedOptions ) {
33+ if ( DISABLE_REDIS_CACHE ) {
34+ return hook => hook ;
35+ }
36+
3237 return function ( hook ) {
3338 try {
3439 if ( hook && hook . params && hook . params . $skipCacheHook ) {
@@ -84,6 +89,10 @@ export default {
8489 } ;
8590 } ,
8691 after ( passedOptions ) {
92+ if ( DISABLE_REDIS_CACHE ) {
93+ return hook => hook ;
94+ }
95+
8796 return function ( hook ) {
8897 try {
8998 if (
@@ -131,6 +140,10 @@ export default {
131140 } ;
132141 } ,
133142 purge ( ) {
143+ if ( DISABLE_REDIS_CACHE ) {
144+ return hook => hook ;
145+ }
146+
134147 return function ( hook ) {
135148 try {
136149 if (
Original file line number Diff line number Diff line change 11import async from 'async' ;
22
3+ const { DISABLE_REDIS_CACHE } = process . env ;
34const HTTP_OK = 200 ;
45const HTTP_NO_CONTENT = 204 ;
56const HTTP_SERVER_ERROR = 500 ;
@@ -157,9 +158,11 @@ export default (options: any = {}) => {
157158 return function ( ) {
158159 const app = this ;
159160
160- app . use ( `${ pathPrefix } /clear/single` , serviceClearSingle ) ;
161- app . use ( `${ pathPrefix } /clear/group` , serviceClearGroup ) ;
162- app . use ( `${ pathPrefix } /clear/all` , serviceClearAll ) ;
161+ if ( ! DISABLE_REDIS_CACHE ) {
162+ app . use ( `${ pathPrefix } /clear/single` , serviceClearSingle ) ;
163+ app . use ( `${ pathPrefix } /clear/group` , serviceClearGroup ) ;
164+ app . use ( `${ pathPrefix } /clear/all` , serviceClearAll ) ;
165+ }
163166 } ;
164167}
165168
You can’t perform that action at this time.
0 commit comments