Hacker News new | ask | show | jobs
by simonrobb 4305 days ago
"Angular-data is very optimistic when it comes to caching. If you do DS.find('user', 5) angular-data will first look for that user in the data store. If that user is already in the data store then the promise returned by DS.find('user', 5) will immediately resolve with the user. If no user exists then (if using the http adapter) a GET request will be made, and the user returned by the server will be injected into the data store."

I couldn't find anything in the docs about invalidation. Is anybody aware of how to force invalidation of an object/collection?

2 comments

you can eject an item or collections of items from the data store with DS.eject and DS.ejectAll. Or you could load angular-cache with angular-data to activate automatic expiry of items (after a timeout or on some interval).
I would probably make an HTTP interceptor to remove the elements from the cache on non-GET methods. The same could probably be done on socket events if you sync your clients with socket.io or something alike.

e.g.: PUT /users/123 => delete from cache the user "123"

This is what I did with angular-cache.