如何刷新/无效在AngularJS $资源缓存 [英] How to refresh / invalidate $resource cache in AngularJS

查看:102
本文介绍了如何刷新/无效在AngularJS $资源缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用默认的$ HTTP缓存实现像这样一个简单的用户资源$

I have a simple User $resource that uses the default $http cache implementation like so:

factory('User', function($resource){
    return $resource(endpoint + '/user/current/:projectId', {},
        {get: 
            {
                cache: true,
                method: 'GET'
            }
        }
    );
})

这工作得非常好,也就是在我的应用我的服务器只叫一次,然后该值从缓存中提取的。

This works very well, i.e. my server is only called once in my application, then the value is fetched from cache.

但我需要一定的操作之后刷新来自服务器的值。有没有一种简单的方法来做到这一点?

But I need to refresh the value from the server after a certain operation. Is there an easy way to do that?

感谢。

推荐答案

请布尔并获得 $ HTTP 缓存:

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

然后,你可以控制它像任何与 $ cacheFactory 做了另一个缓存,下面提供一个使用实例:

Then you can control it like any another cache made with $cacheFactory, a usage instance provided below:

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

这篇关于如何刷新/无效在AngularJS $资源缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆