AJAXCache 1.0

Introduction

AJAXCache 1.0 is a simple script written in JavaScript, which makes it possible to cache data in user's browser memory. AJAXCache meaningfully accelerates time of access to data downloaded earlier. It reduces frequency of communication between browser and server through AJAX. It will certainly matter with web applications.

Download

How to use?

// Define constructor
var cache = new AJAXCache();

// add data to cache
// parameters: ID - [String] identyficator 
//            data - [String] data to caching
//            options - it is not require to give it:
//             *ttl: [Int] 'time to live' - time in seconds, after
//                   that object will be removed
//             *overwrite: [true/false] accept values true or false, implicitly 
//                         it is possible to overwrite object with the same ID after expiration.
cache.save('ID' [String], 'dane' [String], [{ttl: [Int], overwrite: [true/false]}]);

// returns object from cache
// accept parameter ID
cache.get('ID');

// remove object from cache
// accept parameter ID
// removes an item from the cache for a given ID
cache.remove('ID');

// removes all items from cache
cache.flush();

Examples

cache.save('foo', Math.random(), {ttl: 2});

cache.save('foo', Math.random(), {overwrite: true});

cache.save('foo', Math.random(), {ttl: 5000; overwrite: true});

alert(cache.get('foo'));

cache.save('boo', Math.random());

cache.remove('foo');

alert(cache.get('foo'));

cache.flush();

alert(cache.get('foo')+cache.get('boo'));

License

/*
 * AJAXCache 1.0
 *
 * (c) 2007 Jarek Kostrz
 *  e-mail: 
 *  www:  http://ajaxcache.ajaxin.pl
 *        http://ajaxin.pl
 *  http://creativecommons.org/licenses/by/2.5/pl/
 *  In case of commercial use please inform me about that fact.
 */