angular-cache icon indicating copy to clipboard operation
angular-cache copied to clipboard

Cach does not updates data after "put" action

Open ctasci opened this issue 8 years ago • 1 comments

Hi, i am using http requests and custom cache objects to handle the caching. i have a list of customer. if i do a "put" action after i inserted a customer into my db the cache is not updating/it. if i now refresh the site or "removeAll" from my custom cache object it is holding the data.

here's how i create my custom cache-object if (!CacheFactory.get('customerCache')) { customerCache = CacheFactory('customerCache', { maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour deleteOnExpire: 'aggressive' // Items will be deleted from this cache when they expire }); } else { customerCache = CacheFactory.get('customerCache'); } this is how i do the put action: `var customerCache = CacheFactory.get('customerCache');

            var deferred = $q.defer();
            $http.post('/Umbraco/Api/CustomerWebApi/publishCustomer', angular.toJson(customer), {
                cache: customerCache
            }).success(function (data) {
                debugger
                if (data.cError.OK == true) {
                    customerCache.put(data.customer.id, data.customer);
                }
                deferred.resolve(data);
            });
            return deferred.promise;`

and here how i get my list: var customerCache = CacheFactory.get('customerCache'); var deferred = $q.defer(); var start = new Date().getTime(); debugger $http.get('/Umbraco/Api/CustomerWebApi/getAllCustomerByUser', { cache: customerCache }).success(function (data) { console.log('time taken for request: ' + (new Date().getTime() - start) + 'ms'); deferred.resolve(data); }); return deferred.promise; Why is the new inserted data not (visible) in the cach-object ?

ctasci avatar Jul 11 '17 11:07 ctasci

there is an issue in how the cache is handled in case it is an array. please take a look on my comment on #251

MatheusArleson avatar Jun 14 '18 13:06 MatheusArleson