-
-
Save k0pernikus/3853059 to your computer and use it in GitHub Desktop.
Revisions
-
k0pernikus revised this gist
Oct 12, 2012 . 1 changed file with 23 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,31 @@ jQuery.extend({ getCachedJSON: function (url, callback) { var cacheTimeInMs = 3600000; var currentTimeInMs = new Date().getTime(); var cache = { data:null, timestamp:null }; if (typeof window.localStorage[url] !== "undefined") { cache = JSON.parse(window.localStorage[url]); var validCache = (currentTimeInMs - cache.timestamp) < cacheTimeInMs; if (validCache) { callback(cache.data); return true; } } $.getJSON(url, function (data) { cache.data = data; cache.timestamp = new Date().getTime(); window.localStorage[url] = JSON.stringify(cache); callback(cache.data); }); } }); -
k0pernikus revised this gist
Oct 12, 2012 . 1 changed file with 25 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,33 @@ (function ($) { $.extend({ getCachedJSON: function (url, callback) { var cacheTimeInMs = 3600000; var currentTimeInMs = new Date().getTime(); var cache = { data:null, timestamp:null }; if (typeof window.localStorage[url] !== "undefined") { cache = JSON.parse(window.localStorage[url]); var validCache = (currentTimeInMs - cache.timestamp) < cacheTimeInMs; if (validCache) { callback(cache.data); return true; } } $.getJSON(url, function (data) { cache.data = data; cache.timestamp = new Date().getTime(); window.localStorage[url] = JSON.stringify(cache); callback(cache.data); }); } }); }(jQuery)); -
k0pernikus revised this gist
Oct 8, 2012 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,10 +22,7 @@ var getCachedJSON = function (url, callback) { cache.data = data; cache.timestamp = new Date().getTime(); window.localStorage[url] = JSON.stringify(cache); callback(data); }); -
k0pernikus revised this gist
Oct 8, 2012 . 1 changed file with 22 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,32 @@ var getCachedJSON = function (url, callback) { var cacheTimeInMs = 3600000; var currentTimeInMs = new Date().getTime(); var cache = { data:null, timestamp:null }; if (typeof window.localStorage[url] !== "undefined") { cache = JSON.parse(window.localStorage[url]); var validCache = (currentTimeInMs - cache.timestamp) < cacheTimeInMs; if (validCache) { callback(cache.data); return true; } } $.getJSON(url, function (data) { cache.data = data; cache.timestamp = new Date().getTime(); console.log(cache); window.localStorage[url] = JSON.stringify(cache); console.log(window.localStorage[url]); callback(data); }); }; -
k0pernikus revised this gist
Oct 8, 2012 . 2 changed files with 32 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ var getCachedJSON = function (url, callback) { var cacheTimeInMs = 3600000; var currentTimeInMs = new Date().getTime(); var cache = { data:null, timestamp:null }; if (typeof window.localStorage[url] !== "undefined") { cache = JSON.parse(window.localStorage[url]); var validCache = (currentTimeInMs - cache.timestamp) < cacheTimeInMs; if (validCache) { callback(cache.data); return true; } } $.getJSON(url, function (data) { cache.data = data; cache.timestamp = new Date().getTime(); console.log(cache); window.localStorage[url] = JSON.stringify(cache); console.log(window.localStorage[url]); callback(data); }); }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +0,0 @@ -
kpuputti created this gist
Jun 22, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ var getCachedJSON = function (url, callback) { var cachedData = window.localStorage[url]; if (cachedData) { log('Data already cached, returning from cache:', url); callback(JSON.parse(cachedData)); } else { $.getJSON(url, function (data) { log('Fetched data, saving to cache:', url); window.localStorage[url] = JSON.stringify(data); callback(data); }); } };