Comments (13)
Does not fall back if redis is unavailable.
from cache-manager.
BTW, seems I found solution.
enable_offline_queue: false
for internal redis library
from redis doc:
enable_offline_queue | true | By default, if there is no active connection to the Redis server, commands are added to a queue and are executed once the connection has been established. Setting enable_offline_queue to false will disable this feature and the callback will be executed immediately with an error, or an error will be emitted if no callback is specified.
from cache-manager.
when enable_offline_queue:false
if goes inside if here:
https://github.com/NodeRedis/node-redis/blob/4f85030e42da2eed6a178e54994330af5062761e/index.js#L769
if enable_offline_queue:true
https://github.com/NodeRedis/node-redis/blob/4f85030e42da2eed6a178e54994330af5062761e/index.js#L791 ( else case)
self.offline_queue.push(command_obj);
and offline_queue will not proceed until ready status, so without this option, it never calls callback from cache manager, and completely not working( hangs )
RedisClient.prototype.on_ready = function () {
.....
this.send_offline_queue();
this.emit('ready');
}
my code now:
var redisStore = require('cache-manager-redis-store');
let cacheImpl = cacheManager.caching({
store: redisStore,
host:"example.com", // default value
enable_offline_queue:false,
ignoreCacheErrors:true,
db: 0,
ttl: 6000,
prefix: process.env.DATABASE_NAME
});
....
static async wrapQuery( key, query, params )
{
let res = await cacheImpl.wrap(key, async ()=> {
let [rows] = await db.query(query, params);
return rows
});
console.log( res )
return res
}
this works fine
from cache-manager.
@umbobabo - Sorry, I don't have time to add any features now, but I would accept a pull request.
from cache-manager.
In caching.js
this is controlled by passing an ignoreCacheErrors
option: https://github.com/BryanDonovan/node-cache-manager/blob/master/lib/caching.js#L30
...but I just noticed that same option doesn't exist in multi_caching.js
.
from cache-manager.
I'll add this to multi_caching.js
when I get some time (soon hopefully). Do you need it in multi_caching.js
now, or are you just using regular caching.js
?
from cache-manager.
That worked perfectly. Right now I'm only using caching.js. Thank you such a quick reply.
from cache-manager.
ignoreCacheErrors not work with both of redis stores
from cache-manager.
@mogadanez - do you mean when redis is unavailable?
from cache-manager.
exactly, just provide unexisting url for redis.
from cache-manager.
Not sure if enable_offline_queue
will work. It doesn't seem to prevent errors for me. Are you using async/await
? If so, you can probably wrap your calls in a try/catch
block. The issue here is that the ignoreCacheErrors
only ignores errors returned via callbacks and doesn't deal with thrown errors. It would be difficult to wrap the internal caching.js
calls with try/catch
. But if you're using async/await
, it shouldn't be too hard to do the try/catch
in your code.
from cache-manager.
Awesome, glad you figured out a workaround.
from cache-manager.
Thank you @mogadanez for sharing your solution. Unfortunately, we are using multicaching
and the option ignoreCacheErrors
doesn't seem supported. @BryanDonovan Is there any plan to implement ignoreCacheErrors
in multicaching
too?
Thank you for this package.
from cache-manager.
Related Issues (20)
- TypeScript: increase target to ES2017+ HOT 2
- Adding refreshThreshold Parameter to the wrap Function HOT 3
- How to obtain all cached keys at once HOT 1
- 5.3.0 missing `dist/` folder on npmjs.org HOT 28
- Background Refresh can be triggered multiple times. HOT 2
- in NestJS when setting a TTL value, the TTL value is always automatically replaced with the default TTL in the config HOT 5
- Q: question regarding using keys() HOT 1
- Under constant load, backend refresh doesn't provide efficient mechanism to save enought backend request HOT 3
- Memory store: how to set the max value to infinite (only allocate memory on new items) HOT 4
- Support hset hget HOT 1
- Optimizing Multicaching Efficiency: Dynamic Data Migration Between Cache Levels HOT 3
- Add the shouldCloneBeforeSet option to the documentation HOT 1
- cache prefix HOT 1
- Cache error fallback (ters) HOT 4
- Why `Promise` object cannot be store correctly? HOT 2
- prefix configuration option for cache keys HOT 3
- Fs cache store engine HOT 1
- Value being set inside "v" field on new version v2 HOT 2
- Map object is not stored HOT 5
- `this.cacheManager.store.client` is undefined HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cache-manager.