1

When using angular $http, you can set the request configuration cache property to true and the response will be stored. Next time the same request is made, the response is served from the cache without sending a request to the server (docs).

How do you add a (key,val) pair to this cache without performing the http request?

I want to do something like

cache.put("/api/country/uk", someData)

and when $http.get("/api/country/uk") is called later, the cached data is used instead of making the http request.

1 Answer 1

2

I found the solution here. Will keep the question + answer if someone else needs it.

You can get the cache by

var cache = $cacheFactory.get('$http');

and then you can put data to it like this

cache.put("/api/country/uk", someData)

When you call

$http.get("/api/country/uk", {cache:true})

you will get the cached response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.