jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

using as direct replacement in $resource for $cacheFactory doesnt work #161

Closed swilli40 closed 9 years ago

swilli40 commented 9 years ago

I tried using angular-cache, but couldnt get it to store. Tries many things and then tried to just use %cacheFactory instead in a resource. It worked as expected. Size increased.

 cache = $cacheFactory.get('tagCloudCache2') || $cacheFactory('tagCloudCache2');    ** works **

 cache = DSCacheFactory.get('tagCloudCache') ||  DSCacheFactory('tagCloudCache', {
                    maxAge:  5 * 60 * 1000, // 5 mins
                    deleteOnExpire: 'aggressive'
                });  ** doesnt work **

calling with:

return customResource('x/:xId/tags/_cloud', {xId: sId}, cache).query().$promise.then

using custom resource:

.factory('customResource', ['$resource','baseUrls','$rootScope',
        function($resource, baseUrls, $rootScope){
            return function (url, params, cache){

                function formatResponse(data, headersGetter) {
                  ....
                }

                return $resource(
                    baseUrls.api+'/'+url+'/',
                    params,
                    {
                        get:    {method:'GET', transformResponse:formatResponse, cache:cache},
                        query:  {method:'GET', transformResponse:formatResponse, cache:cache},
                        update: {method:'PUT'}
                    }
                );
            };
}])
jmdobry commented 9 years ago

Try with angular-cache 2.x. Angular-cache 4.x should work better with ngResource.

swilli40 commented 9 years ago

Thanks. Is there an issue with 3.0? I thought it was meant for drop in replacement.

Cheers Shane

On 16 Mar 2015, at 02:18, Jason Dobry notifications@github.com wrote:

Try with angular-cache 2.x. Angular-cache 4.x should work better with ngResource.

— Reply to this email directly or view it on GitHub.

jmdobry commented 9 years ago

There is one specific assumption that only ngResource makes about the implementation of a cache, which (I think) prevents angular-cache 3.x from being used with ngResource. This is discussed in two other issues. 3.x works fine if you're not using ngResource. 4.x will work with ngResource.

swilli40 commented 9 years ago

cool, thanks for speedy reply. Any issues with using 2.x until 4.x? Shane

Date: Mon, 16 Mar 2015 08:13:16 -0700 From: notifications@github.com To: angular-cache@noreply.github.com CC: swilli40@hotmail.com Subject: Re: [angular-cache] using as direct replacement in $resource for $cacheFactory doesnt work (#161)

There is one specific assumption that only ngResource makes about the implementation of a cache, which (I think) prevents angular-cache 3.x from being used with ngResource. This is discussed in two other issues. 3.x works fine if you're not using ngResource. 4.x will work with ngResource.

— Reply to this email directly or view it on GitHub.

jmdobry commented 9 years ago

No, though 2.x has some deprecated parts that won't be in 4.x

swilli40 commented 9 years ago

tried with 2.4.1, get the same….

thanks

Shane

On 16 Mar 2015, at 15:15, Jason Dobry notifications@github.com wrote:

No, though 2.x has some deprecated parts that won't be in 4.x

— Reply to this email directly or view it on GitHub https://github.com/jmdobry/angular-cache/issues/161#issuecomment-81727425.

jmdobry commented 9 years ago

Can you create a plunker of jsfiddle that demonstrates the issue?

jmdobry commented 9 years ago

Should be fixed in 4.0.0

jmdobry commented 9 years ago

ngResource is now officially support in 4.1.0