AngularJS $http cache expiration time

Can you set an expiration time for Angular’s $http default caching system ? I would like that an URL stays in the cache for 1 minute, so that any requests made to it after 1 minute grabs fresh data from the server.

Answer

There is no way to set the expiration time. But you can do it manually. You have to access the $http cache:

var cache = $cacheFactory.get('$http');

and remove the url that is cached by:

cache.remove(theUrl);

See documentation for more information.

Leave a Reply

Your email address will not be published. Required fields are marked *