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

Implement cache invalidation #32

Open
KieronWiltshire opened this issue Mar 21, 2017 · 3 comments
Open

Implement cache invalidation #32

KieronWiltshire opened this issue Mar 21, 2017 · 3 comments

Comments

@KieronWiltshire
Copy link

KieronWiltshire commented Mar 21, 2017

So what I'd like to see implemented, is if the "create" method or similar is executed, then the cache will be invalidated.

For example, if I do a findAll, then a create, and repeat the findAll, I'd like to be able to retrieve the latest included within that find.

Is this possible?

@ColonelBundy
Copy link

Yes this is possible, you can achieve this by adding hooks and implement the logic for invalidation there.

Example:

Model.hook('afterCreate', function(instance, options) {
  // Invalidate/update cache here
};

Model.hook('afterDestroy', function(instance, options) {
  // Invalidate/update cache here
}; 

Model.hook('afterUpdate', function(instance, options) {
  // Invalidate/update cache here
};

Model.hook('afterSave', function(instance, options) {
  // Invalidate/update cache here
};

Model.hook('AfterUpsert', function(created, options) {
  // Invalidate/update cache here
}; 

@KieronWiltshire
Copy link
Author

Thanks man!

@idangozlan
Copy link

@KieronWiltshire
If you are using Sequelize 4, check out that module:

https://github.com/idangozlan/sequelize-redis

It's a full solution for caching + invalidating cache easily, and as much as I know it's the only Sequelize 4 caching module (right now).

Disclaimer: I'm the author of that module and I'm using that on production for daily traffic of 1m unique users.

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