angularjs: how to add caching to resource object?

后端 未结 8 670
栀梦
栀梦 2020-12-02 08:08

To add caching inside http is pretty straight forward. ( by passing cache=true )

http://docs.angularjs.org/api/ng.$http has Cache option.

How do I add simila

8条回答
  •  一生所求
    2020-12-02 08:53

    You can also set default cache for $http and thus for $resource which is based on it.

    My settings with the excellent angular-cache allowing LocalStorage and compliant with $cacheFactory:

    app.run(function($http, DSCacheFactory) {
    
        DSCacheFactory('defaultCache', {
            deleteOnExpire: 'aggressive',
            storageMode: 'localStorage' 
        });
    
        $http.defaults.cache = DSCacheFactory.get('defaultCache');
    });
    

提交回复
热议问题