I created a UserService as follows:
angular.module('nrApp').factory('userService', ['Restangular', 'UserModel', 'DSCacheFactory', function (Restangular, UserModel, DSCacheFactory) { // Create a new cache called "profileCache" var userCache = DSCacheFactory('userCache', { maxAge: 3600000, deleteOnExpire: 'aggressive', storageMode: 'localStorage', // This cache will sync itself with `localStorage`. onExpire: function (key, value) { Restangular.oneUrl('users', key).get().then(function(data) { userCache.put(key, data); }); } }); Restangular.extendModel('users', function(obj) { return UserModel.mixInto(obj); }); Restangular.addRequestInterceptor(function(element, operation, what, url) { if(operation === 'get') { debugger; //Check the cache to see if the resource is already cached var data = userCache.get(url); //If cache object does exist, return it if(data !== undefined) { angular.extend(element, data); } return element; } }); Restangular.addResponseInterceptor(function(data, operation, what, url, response) { //Cache the response from a get method if(operation === 'get') { debugger; userCache.put(url, data); } //Unvalidate the cache when a 'put', 'post' and 'delete' is performed to update the cached version. if (operation === 'put' || operation === 'post' || operation === 'delete') { userCache.destroy(); } return response; }); return Restangular.service('users'); }]);
From the comments, itβs clear that what I'm trying to achieve is whenever the Get request is executed through this service using Restangular, the local cache is checked, and if the cache returns an object, it expands into a restatular element. The thread that needs to be reached is to cancel a segment request when a cache object is found for this request.
However, without luck, the addResponseInterceptor method is still executing, although the object was found in the cache.
Are there any possible solutions for canceling a server request during a get request?
Thanks!:)