加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在AngularJS中刷新/使$resource缓存失效

发布时间:2020-12-17 09:11:15 所属栏目:安全 来源:网络整理
导读:我有一个简单的User $资源,使用默认的$ http缓存实现像这样: factory('User',function($resource){ return $resource(endpoint + '/user/current/:projectId',{},{get: { cache: true,method: 'GET' } } );}) 这工作得很好,即我的服务器只在我的应用程序
我有一个简单的User $资源,使用默认的$ http缓存实现像这样:
factory('User',function($resource){
    return $resource(endpoint + '/user/current/:projectId',{},{get: 
            {
                cache: true,method: 'GET'
            }
        }
    );
})

这工作得很好,即我的服务器只在我的应用程序中调用一次,然后从缓存中获取值。

但是我需要在执行某个操作后从服务器刷新值。有没有一个简单的方法来做到这一点?

谢谢。

保持布尔值并获得$ http缓存:
var $httpDefaultCache = $cacheFactory.get('$http');

然后你可以控制它像任何其他缓存用$ cacheFactory,使用实例提供如下:

$httpDefaultCache.remove(key);
// Where key is the relative URL of your resource (eg: /api/user/current/51a9020d91799f1e9b8db12f)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读