如何刷新/使AngularJS中的$ resource缓存无效

亚历山大·布特(AlexandreBulté)

我有一个简单的User $ resource,它使用默认的$ 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)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章