Closed pishguy closed 7 years ago
Hello and thanks for the feedback. If I understand correctly, you want the module to check the database for each cache hit? Wouldn't that negate the benefit of caching?
@rfink Thanks sir,
I'm not sure that is best practice, i dont see any setting to renew cache after that, for example timeout, after that cache automatically refresh with new data when we want to get query,
check time out and refresh with new data, or other best practice for this solution
If I understand correctly, I believe you're looking for the ttl functionality that the library contains. You can set the ttl (time-to-live) in seconds, after which the cache expires and new data will be fetched. Is that what you're looking for?
its ok, how can i set ttl? and i have another question. can i force clear cache contains? to read again from database and caching that when i try to get query from database
Setting ttl by:
cacher('modelName').ttl(60).find({ / Query here /});
60 would mean 60 seconds. Since the module uses redis, this is implemented as a ttl on redis. You can set it as low as 0, and as high as redis will allow.
As far as manually clearing, you can use:
clearCache(queryObject)
If you want to see an example of using this, check out the unit tests.
Thanks for using the module!
@rfink Thanks
when this library use cache and retrieve from cache can check data updated on database or not? for example when this library retrieve data from cache first check database, if data updated clear from cache and re-chache again and send for user