I'm struggling with caching a JSONP request and have tested out different approaches without success.
I attempted
$http.jsonp(url, { cache: true })
and $http({ method: 'JSONP', url: url, cache: true })
, but neither worked as expected.
As a workaround, I've implemented manual caching of the results (a basic example provided below).
Is there a way for AngularJS to handle this caching automatically?
countries.factory 'Wikipedia',
['$http', '$q', ($http, $q) ->
cache = {}
getSummary: (country) ->
if cache.hasOwnProperty(country)
cache[country]
else
summary = $q.defer()
url = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=0&rvparse=1&titles=#{country}&format=json&redirects=1&callback=JSON_CALLBACK"
$http.jsonp(url).success (data) ->
# process data ....
paragraphs = ['p1', 'p2']
# return summary content paragraphs
cache[country] = paragraphs
summary.resolve paragraphs
summary.promise
]