Does anyone can help me with caching a json string in Trigger.io? I have a lot of json request for which i think its a good idea to cache them for say 1 hour for example. According to the jquery manual about $.ajax(Trigger.io points to this manual for forge.request.ajax) there is no caching for jsonp and script as a type but i’m using json here so i was hoping to do some caching on it.
I’m using the forge.request.ajax like so:
forge.request.ajax({
url: the_url_to_api,
dataType: 'json',
cache: true,
success: function(data) {
parsed_template = _.template( $('#sales_index_template').html(), {nowOnSale: data.activeSales, soonOnSale: data.upcomingSales } );
app.end_set_right_content(parsed_template);
},
error: function(error) {
alert('Request for sales failed');
}
});
And this are my headers for the json return script in the API
- Date Tue, 28 Aug 2012 15:19:30 GMT
- x-powered-by PHP/5.3.15
- Connection Keep-Alive
- Content-Length 4294
- Pragma cache
- Server Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8g PHP/5.3.15
- Content-Type application/json; charset=utf-8
- Cache-Control max-age=3600
- Keep-Alive timeout=5, max=100
- Expires Tue, 28 Aug 2012 16:19:30 GMT
With the above settings there is no caching going on if i look in chromes or safaris network debugger.. Maybe someone can help me with what i’m doing wrong? or maybe somebody has a better idea for caching in Trigger.io?
Thanks in advanche!
In a recent application I developed I cache (in memory) the resulting json until the user presses the little “refresh” icon. I guess I could add an extra user preference setting to automatically expire in x days. Also, instead of using memory I could have utilized trigger.io to save the json to disk.
Here is the app if you want to see how I do it (Note: I committed a couple of untested tweeks this morning):
https://github.com/dragthor/south-ridge-app
The viewmanager.js handles most of the backbone.js model caching logic. Basically I do the usual: