You can implement your storage layer as a $cacheFactory and add it to $httpProvider during the configuration phase.
From the docs:
When the cache is enabled, $http stores the response from the server in the specified cache. The next time the same request is made, the response is served from the cache without sending a request to the server.
Hence, if you provide your own implementation of a cache with the following methods:
- {object} info() — Returns id, size, and options of cache.
{{*}}
put({string} key,{*}
value) — Puts a new key-value pair into the cache and returns it.{{*}}
get({string} key) — Returns cached value for key or undefined for cache miss.- {void} remove({string} key) — Removes a key-value pair from the cache.
- {void} removeAll() — Removes all cached values.
- {void} destroy() — Removes references to this cache from $cacheFactory.
You can return values read from localStorage
, session cookies, etc. and they will be treated as there were data
sent from the server, just without the AJAX request.