@@ -67,7 +67,7 @@ class TryCache {
6767 * If it succeeds it will return the cached value, and update the cache in the background.
6868 * @param key - the key to get.
6969 * @param retrieveFunction - the function to call if the key is not found in cache. <() => func(...params)>.
70- * @param opts - the options to use: { expire: number, callbackFunction: Function }.
70+ * @param opts - the options to use: { expire: number, callbackFunction: Function, forceDB: boolean }.
7171 * @returns the requested cache value, or the result of the retrieveFunction
7272 * if no cache value is found.
7373 */
@@ -81,10 +81,16 @@ class TryCache {
8181 callbackFunction : opts ?. callbackFunction
8282 ? opts . callbackFunction
8383 : defaults . defaultCallbackFunction ,
84+ forceDB : opts ?. forceDB ? opts . forceDB : false ,
8485 } ;
8586 try {
86- const cachedValue = await this . safeGetFromCache ( key ) ;
87- // If no value found, retrieve from DB and set
87+ let cachedValue ;
88+
89+ if ( ! operationOpts . forceDB ) {
90+ cachedValue = await this . safeGetFromCache ( key ) ;
91+ }
92+
93+ // If no value found or forceDB activated, retrieve from DB and update cache
8894 if ( ! cachedValue ) {
8995 const result = await retrieveFunction ( ) ;
9096 await this . safeSetCache ( key , result , operationOpts . expire ) ;
0 commit comments