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

$http cache invalidation API #2079

Closed
spolu opened this issue Feb 27, 2013 · 6 comments
Closed

$http cache invalidation API #2079

spolu opened this issue Feb 27, 2013 · 6 comments

Comments

@spolu
Copy link

spolu commented Feb 27, 2013

It would greatly extend the use of the $http cache mechanism if we could invalidate the cache content for a specific URL so that any subsequent request on that URL would go the the actual server:

$http.invalidate(some_url)
@jbdeboer
Copy link
Contributor

This will become fairly use with request interceptors, discussed in #1701 and #1851 . e.g. you could just set the cache-control max-age header for specific URLs.

At that point, I don't think a specific $http.invalidate API makes sense.

@ashtuchkin
Copy link
Contributor

I believe HTTP cache has nothing to do with this issue. He asks about Angular's own http cache.

Current workaround: use custom cache (use $cacheFactory to create it and provide it as cache in http config for every request. I'll make a pull request so that you'll be able to do that in $http.defaults). You'll have full control of it, including removing entries.

@jbdeboer
Copy link
Contributor

I do like the #2084 approach, which would make $http's cache invalidation possible. I'm still not convinced it is a good idea, because the app developer would need to set the HTTP headers for the request to ensure the request made it back to the origin server.

@ashtuchkin
Copy link
Contributor

Aren't HTTP cache headers set by server side?

@jbdeboer
Copy link
Contributor

The client has some control, mainly through setting "max-age: 0" and setting the "If-Modified-Since" header.. c.f. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.1.6

Angular's $http cache is not HTTP-compliant. (e.g. doesn't respect age headers). It probably should be.

@ashtuchkin
Copy link
Contributor

Thanks James, I wasn't aware of that. So, making Angular's $http cache HTTP-compliant could be another pull request :)

Anyway, in current state, the app developer can ensure that specific urls are not cached (that's what @spolu was asking for originally) by providing headers from server. This is the main cache controlling mechanism in HTTP. Having done that, app developer doesn't need to provide any additional client headers, correct me if I'm wrong.

Having said that, I would not use $http cache at all, as the browser usually does a good job caching requests and all the HTTP cache headers are there for a reason.

ashtuchkin added a commit to ashtuchkin/angular.js that referenced this issue Mar 5, 2013
When we need more control over http caching, we may want to provide
a custom cache to be used in all http requests by default.

To skip default cache, set {cache: false} in request configuration.
To use other cache, set {cache: cache} as before.

See angular#2079
jbdeboer pushed a commit to jbdeboer/angular.js that referenced this issue Mar 8, 2013
When we need more control over http caching, we may want to provide
a custom cache to be used in all http requests by default.

To skip default cache, set {cache: false} in request configuration.
To use other cache, set {cache: cache} as before.

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

No branches or pull requests

3 participants