https://github.com/thinkphp/cache.js
Wrapper to store the results in localStorage HTML5 when the browser support it with timed expiry.
https://github.com/thinkphp/cache.js
Last synced: 3 months ago
JSON representation
Wrapper to store the results in localStorage HTML5 when the browser support it with timed expiry.
- Host: GitHub
- URL: https://github.com/thinkphp/cache.js
- Owner: thinkphp
- Created: 2012-02-20T12:53:44.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-02-23T20:12:31.000Z (almost 14 years ago)
- Last Synced: 2024-04-14T14:54:23.159Z (almost 2 years ago)
- Language: JavaScript
- Homepage: http://thinkphp.ro/apps/js-hacks/cache.js/
- Size: 97.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
cache.js
========
Wrapper to store the results in localStorage HTML5 when the browser support it with timed expiry.

How to use
----------
var $ = function(id){return document.getElementById(id);}
var getflickrbybadge = function() {
//private member
var bigImage = null;
function init() {
if(Cache.get('mybooksflickr')) {
var photos_cached = Cache.get('mybooksflickr');
$('results').innerHTML = photos_cached;
$('status').innerHTML = '(read from cache)';
} else {
asyncRequest.REQUEST('GET','getphotosfromjson.php?sid='+Math.random(),getflickrbybadge.seed);
}
};
function seed(o) {
$('results').innerHTML = o
Cache.set('mybooksflickr',o)
$('status').innerHTML = 'read from api (fresh)'
}
function show(o) {
if(bigImage == null) {
bigImage = document.createElement('div');
bigImage.style.position = 'absolute';
bigImage.style.left = '300px';
bigImage.style.border = '5px solid #ccc';
bigImage.style.padding = '4px';
document.body.appendChild(bigImage);
};//endif
var output = o.innerHTML.replace(/_s/,'_m');
bigImage.innerHTML = '' + output + '';
bigImage.style.display = 'block';
var y;
if(self.pageYOffset) {
y = self.pageYOffset;
} else if(document.documentElement && document.documentElement.scrollTop) {
y = document.documentElement.scrollTop;
} else if(document.body) {
y = document.body.scrollTop;
}
bigImage.style.top = 100 + y + 'px';
};
return {init: init,show: show,seed: seed}
}();
Cache.expiry = 60*60*1000;
getflickrbybadge.init();
I used cache.js in my blog: thinkphp.ro/blog @section reading
You can view in action: http://thinkphp.ro/apps/js-hacks/cache.js/