I read about the Angular '$cacheFactory' but could not find any documentation on setting an expiration date for cached content.
What if I want to cache all GET requests for 30 seconds, how to I define this in the '$cacheFactory' or do I need to extend the functionality myself.
I faced the problem too. The default $cacheFactory have no time to live (TTL).
You will need to implement this yourself. But before, you could give a look around, to see if someone already did it :
This one look pretty complete - http://jmdobry.github.io/angular-cache/
If you really want to implement your own solution (by implementing your own $cacheFactory) and need some help, feel free to ask.
Hope it gave you some clue.
for TTL 1h, see below example
add factory:
then init in config push your interceptor. An interceptor is simply a regular service factory that is registered to that array.
example of request
Constant is:
I think @miukki answer's is great. Adding my modification to the request of @Vil
I modified the 'request' function of the 'cacheInterceptor' to use $timeout instead of relying on Date. It allows TTL to be more global for requests, So if one request sets a TTL and the 2nd doesn't but data is still in cached, it will still be used.