jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

Third option to aggressive and passive delete. #30

Closed CMCDragonkai closed 11 years ago

CMCDragonkai commented 11 years ago

I have a situation, where I don't want the cache to immediately delete items that have expired. This is because I need to check if I can update the old item with a request to a third party service, if that third party service rejects my request, I need access to the old cached item and have the option to reset the expiry.

Any ideas on how to achieve that? I see that both passive and aggressive delete both deletes the item when it has been invalidated.

jmdobry commented 11 years ago

It looks like the feature described in #27 is what you are looking for.

Right now, passive delete (which is the default) doesn't delete the item right when it expires. The expired item is still in the cache. But if you request the expired item, it is immediately deleted. The feature described in #27 is the ability to specify a callback that will be executed when the item expires. The expired item will be passed as an argument to that callback. In that callback you could do the following:

Does that seem like it would work for you?

CMCDragonkai commented 11 years ago

In the second example, is the done() function the same as the callback passed into the get's third parameter? Yes it could work, but it does require some manual programming. Would prefer it if you had a soft get function, that would allow the ability to get the item without deleting it.

jmdobry commented 11 years ago

K, I'll work something out.

How about three levels:

CMCDragonkai commented 11 years ago

That sounds great.

jmdobry commented 11 years ago

47