Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High performance/availability cache setup - feature request #62

Closed
PuKoren opened this issue Aug 2, 2016 · 7 comments
Closed

High performance/availability cache setup - feature request #62

PuKoren opened this issue Aug 2, 2016 · 7 comments

Comments

@PuKoren
Copy link
Contributor

PuKoren commented Aug 2, 2016

Hello!

I'm currently adding a new feature to node-cache-manager. However I am not sure of the way to go yet, because I can't find a consistent API for the available stores.

The idea of the feature request is to add an always available, low latency multi store setup. This way even if our frontend server loses connection to backend for whatever reason, it will keep working at maximum speed for our front users.

Idea for the high perf/high availability setup using node-cache-manager:

Using a multi store, and wrap method

  • First store have a TTL of 0 (always resolve, keep data forever)
  • Secondary stores have a TTL > 0 (fetched from it if not in primary store, expires after TTL)
  • When data expires from secondary store, data is still returned immediately from first store, while secondary store is being updated, once done primary store will be updated too.

However, since API of stores is not defined, I can't have access to TTL, expired date/time of keys, etc. and of course I don't want to call .get on each store every time wrap is called, to check if it contains the key in order to update it.

Any idea on how to implement this in an efficient manner?

Feature specs available here: dial-once@9948303

@BryanDonovan
Copy link
Collaborator

Are you saying you need methods like cacheStore.getTtl()?

@PuKoren
Copy link
Contributor Author

PuKoren commented Aug 3, 2016

Something like that, for a given key. It will be needed for this feature

I can add it to memory cache, as well as redis cache, but for other caches it may cause the feature to not work because this method wont be available. Any idea for this?

@BryanDonovan
Copy link
Collaborator

I suppose this could just be added like it is in caching.js:

    /**
     * Binds to the underlying store's `ttl` function if it exists.
     * @function
     * @name ttl
     */
    if (typeof self.store.ttl === 'function') {
        self.ttl = self.store.ttl.bind(self.store);
    }

Your new feature should probably check if the ttl function exists before trying to use it.. or maybe throw an error so it fails hard.

@PuKoren
Copy link
Contributor Author

PuKoren commented Aug 3, 2016

Thanks for your answer, I will assume that .ttl function is required for this feature then. I would like to keep backward compatibility so I don't think I will throw any error, but rather disabling the feature if ttl function is undefined on one of the stores.

@BryanDonovan
Copy link
Collaborator

I think this sounds good. This should probably be something a user enables via config. Something like autoUpdateLowerPriorityCaches: true (hopefully you can think of a better name though).

@PuKoren
Copy link
Contributor Author

PuKoren commented Aug 4, 2016

Ok, will go for a config var then, thanks for your inputs!

@amit777
Copy link

amit777 commented Aug 21, 2017

@PuKoren I was looking to do something almost exactly the same (in fact your solution sounds better than what I was thinking). Did you end up creating something for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants