AngularJS $ http缓存到期时间

Adr*_*atu 13 angularjs

你能为Angular的$ http默认缓存系统设置一个到期时间吗?我希望URL保留在缓存中1分钟,以便1分钟后向它发出的任何请求都会从服务器获取新数据.

mic*_*ael 9

无法设置到期时间.但你可以手动完成.您必须访问$ http缓存:

var cache = $cacheFactory.get('$http');
Run Code Online (Sandbox Code Playgroud)

并删除缓存的网址:

cache.remove(theUrl);
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅文档