Using localStorage will give you persistence across sessions. Something
like:
function getDataTable(datasourceUrl, callback) {
var cached_data = null;
if (window.localStorage) {
cached_data = window.localStorage['cachedDataTable']
}
if (cached_data) {
var dt = new google.visualization.DataTable(cached_data);
callback(dt);
} else {
new
google.visualization.Query(datasourceUrl).send(function(queryResponse) {
// omissis: check for errors
dt = queryResponse.getDataTable();
if (window.localStorage) {
window.localStorage['cachedDataTable'] = dt.toJSON();
}
callback(dt);
});
}
}
Which you'd use like:
getDataTable(datasourceUrl, function(dataTable) {
// dataTable here is either the cached one or the live one.
});
Note that I haven't tested the code above, so it may be faulty. We used a
similar solution for the Google I/O presentation. See this
file<http://code.google.com/p/google-visualization-io2011/source/browse/js/rosling.js>(lines
50-60 and 140-150).
You'd also need some extra logic to handle expiration of the local cache.
/R.
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/QzB3M1cxVFg1VEVK.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.