Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$http : ability to clear a request from the cache #5968

Open
njs50 opened this issue Jan 23, 2014 · 3 comments
Open

$http : ability to clear a request from the cache #5968

njs50 opened this issue Jan 23, 2014 · 3 comments

Comments

@njs50
Copy link

njs50 commented Jan 23, 2014

At the moment there isn't a direct way in $http to clear the cache.

I know it's possible to use $cacheFactory to return the default or custom cache.
However to be able to use this with 100% confidence i'd also need the buildUrl function from $http exposed to generate the key.

so it'd be nice if we had either:

$http.buildUrl(url,params) made public

or something like:

$http.removeCache(url, params (optional), cache (optional))

If either of those sounds like they'd be a good idea I'm happy to put together a PR for it...

@btford btford added this to the Ice Box milestone Feb 18, 2014
njs50 added a commit to njs50/angular.js that referenced this issue Feb 19, 2014
…e a request overwrite an existing value in the cache angular#5968
njs50 added a commit to njs50/angular.js that referenced this issue Feb 19, 2014
…ests in $http cache

Adds $http.removeCache method.
Adds/implements replaceCache property in $http request configuration.

Closes angular#5968
njs50 added a commit to njs50/angular.js that referenced this issue Feb 19, 2014
…ests in $http cache

Adds $http.removeCache method.
Adds/implements replaceCache property in $http request configuration.

Closes angular#5968
njs50 added a commit to njs50/angular.js that referenced this issue Mar 3, 2014
…ests in $http cache

Adds $http.removeCache method.
Adds/implements replaceCache property in $http request configuration.

Closes angular#5968
@btford btford removed the gh: issue label Aug 20, 2014
njs50 added a commit to njs50/angular.js that referenced this issue Nov 17, 2014
…ests in $http cache

Adds $http.removeCache method.
Adds/implements replaceCache property in $http request configuration.

Closes angular#5968
njs50 added a commit to njs50/angular.js that referenced this issue Nov 17, 2014
…ests in $http cache

Adds $http.removeCache method.
Adds/implements replaceCache property in $http request configuration.

Closes angular#5968
njs50 added a commit to njs50/angular.js that referenced this issue Nov 17, 2014
…ests in $http cache

Adds $http.removeCache method.
Adds/implements replaceCache property in $http request configuration.

Closes angular#5968
@jmendiara
Copy link
Contributor

@njs50 Take a look to https://github.com/angular-hu/angular-hu/tree/develop/src/headers . I'm using it to remove requests from the cache

@njs50
Copy link
Author

njs50 commented May 7, 2015

@jmendiara that looks handy, my issue is more that I don't think it's a good idea to have a cache where you can't remove things without having to modify/decorate the core code in some way.

currently I do both:

  1. invalidate an $http cache without requesting new data
  2. invalidate an $http cache and repeat the request to repopulate the cache

(1) is usually in response to something that happened on a remote system and (2) is in reaction to something the user has done.

@jmendiara
Copy link
Contributor

@njs50 Agree, httpu.headers gives you the cache key for a specific request, so the controlller/service can invalidate them. It's a foundation to implement your specific app business logic.

$http.get('/api', {
  cache: myCacheImpl
})
.then(function(response) {
  $scope.cacheKey = response.headers('httpu-request-url'); //store to react on user action (2)
})
.catch(function(rejection) {
  if (rejection.data.error) { //your app condition for (1)
    rejection.config.cache.remove(rejection.headers('httpu-request-url')); //or directly myCacheImpl
  }
});

You can also take a look to httpu.urlbuilder to re-calculate the request-url.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants