GithubHelp home page GithubHelp logo

cache error fallback about cache-manager HOT 13 CLOSED

jaredwray avatar jaredwray commented on July 17, 2024 1
cache error fallback

from cache-manager.

Comments (13)

raj-krrish avatar raj-krrish commented on July 17, 2024 3

Does not fall back if redis is unavailable.

from cache-manager.

mogadanez avatar mogadanez commented on July 17, 2024 1

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.

mogadanez avatar mogadanez commented on July 17, 2024 1

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.

BryanDonovan avatar BryanDonovan commented on July 17, 2024 1

@umbobabo - Sorry, I don't have time to add any features now, but I would accept a pull request.

from cache-manager.

BryanDonovan avatar BryanDonovan commented on July 17, 2024

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.

BryanDonovan avatar BryanDonovan commented on July 17, 2024

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.

jpaolini avatar jpaolini commented on July 17, 2024

That worked perfectly. Right now I'm only using caching.js. Thank you such a quick reply.

from cache-manager.

mogadanez avatar mogadanez commented on July 17, 2024

ignoreCacheErrors not work with both of redis stores

from cache-manager.

BryanDonovan avatar BryanDonovan commented on July 17, 2024

@mogadanez - do you mean when redis is unavailable?

from cache-manager.

mogadanez avatar mogadanez commented on July 17, 2024

exactly, just provide unexisting url for redis.

from cache-manager.

BryanDonovan avatar BryanDonovan commented on July 17, 2024

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.

BryanDonovan avatar BryanDonovan commented on July 17, 2024

Awesome, glad you figured out a workaround.

from cache-manager.

umbobabo avatar umbobabo commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.