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

$http cache docs are not clear #11101

Closed
Fonger opened this issue Feb 18, 2015 · 2 comments
Closed

$http cache docs are not clear #11101

Fonger opened this issue Feb 18, 2015 · 2 comments

Comments

@Fonger
Copy link

Fonger commented Feb 18, 2015

According to the docs,
it says

To enable caching, set the request configuration cache property to true (to use default cache) or to a custom cache object (built with $cacheFactory)
You can change the default cache to a new object (built with $cacheFactory) by updating the $http.defaults.cache property. All requests who set their cache property to true will now use this cache object.
If you set the default cache to false then only requests that specify their own custom cache object will be cached.

I'm confused by the default value. The doc doesn't specify this.
So I run $http.defaults.cache and gets undefined. So will it ignore all cache-control header? It seems that this is not true.

I have the following question:

  1. If cache is true, it will follow the http cache-control header and store the cache in browser cache. Is this correct? If it's true but the server doesn't reply cache-control header, it won't cache.
  2. If cache is false it won't cache even if the server reply cache-control header.
  3. If it's a CacheFactory object, then the object will handle it. Also ignore the cache-control header.
@pkozlowski-opensource
Copy link
Member

@Fonger I can sense confusion about how $http cache works in AngularJS atm. So, in short, it is a simple cache that doesn't inspect response headers. You simply tell it to cache responses and if it will do so if asked, regardless of the response content, headers etc. So the cache-control header has no effect on the AngularJS cache.

Does it clarify things? Would you be up to sending us a doc update PR with the clarification you would like to see in the docs?

@pkozlowski-opensource pkozlowski-opensource added this to the Backlog milestone Feb 21, 2015
@Narretz Narretz changed the title $http cache $http cache docs are not clear Feb 22, 2015
@ryanhart2
Copy link
Contributor

I have submitted PR #13003 to address this.

gkalpak pushed a commit that referenced this issue Feb 17, 2016
Included changes:

* Point out that only GET & JSONP requests are cached.
* Explain that the URL+search params are used as cache keys (headers not considered).
* Add note about cache-control headers on response not affecting Angular caching.
* Mention `$httpProvider.defaults.cache` (in addition to `$http.defaults.cache`).
* Clear up how `defaults.cache` and `config.cache` are taken into account for determining the
  caching behavior for each request.

Fixes #11101
Closes #13003
gkalpak pushed a commit that referenced this issue Feb 17, 2016
Included changes:

* Point out that only GET & JSONP requests are cached.
* Explain that the URL+search params are used as cache keys (headers not considered).
* Add note about cache-control headers on response not affecting Angular caching.
* Mention `$httpProvider.defaults.cache` (in addition to `$http.defaults.cache`).
* Clear up how `defaults.cache` and `config.cache` are taken into account for determining the
  caching behavior for each request.

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

No branches or pull requests

3 participants