为 $resource 中的 $CacheFactory 缓存提供自定义键值

Providing custom key value for $CacheFactory cache in $resource

根据 AngularJS 文档,$resource 服务现在也支持缓存。

cache – {boolean|Cache} – If true, a default $http cache will be used to cache the GET request, otherwise if a cache instance built with $cacheFactory, this cache will be used for caching.

所以我可以这样写$resource:

app.factory('myResourceWithCache', function($resource, $cacheFactory) {
    var myCache = $cacheFactory('MyCache');
    return $resource(apiBaseUrl + '/myservice/:id', {id: '@id'}, {
        'get': { method:'GET', cache: myCache },
        'query': { method:'GET', cache: myCache , isArray:true }
    });
});

我想知道的是:

  1. 缓存中的键名是什么?对于$http缓存,key是service/api的路径,如果我们使用自定义缓存是不是一样?
  2. 有没有办法自己为自定义缓存(此处为 myCache)提供键名​​

我尝试了 AngularJS 文档和其他 Whosebug 线程,但没有找到任何答案。请帮忙

我不确定你是否还需要回答这个已有一年历史的问题。

Angular Documentation $http - Caching section 没有提到自定义键

并且在 $http 库中,自定义或默认缓存将使用 this line to "put" cache,这是请求 url。

所以回答你的问题:

  1. 请求URL。是的,客户缓存也是如此
  2. 没有(至少到现在为止)