-
JSOC Framework
An Object Cache Framework for JavaScript
ver. 0.12.0-beta (released November 28, 2006)[ JSOC-0.12.0-beta.js ] - source code only
[ JSOC-0.12.0-beta.zip ] - compressed source code + docs
Status: Beta
The JSOC framework is a pluggable, extensible, open source client-side caching framework for Web 2.0 applications.
JSOC offers Web developers a straightforward way to perform common caching techniques (add, replace, remove, flush, etc.) inside any Ajax-ready browser.
Since JSOC is a standalone JavaScript module, incorporating JSOC into a Web development project is a matter of including a script reference, and working with common caching methods. Low-level methods are contained in the JSOC JavaScript module so that developers can focus on the Web development task at hand.
JSOC source is licensed under the BSD license.
Tip of the day: JSOC can retrieve cached objects by object type!
Methods: Note - Method signatures align closely with the wonderful memcached product- set(cacheItemName: String, CacheItemValue: Object, [{'ttl':'milliseconds'}]): Int
-
// Unconditionally sets a given key with a given value.
// If method returns 1, all is well.
// Optional argument "ttl" = 'time to live' and will clear
// the given cache item after the specified number of milliseconds.// Optional arguments ('time to live' [ttl] at the moment) are
// passed as a JSON object; {"ttl":"5000"} for example.Example:
// create a JSOC instance.
jsoc = new JSOC();
// set foo to cache with a value of bar.
jsoc.set('foo','bar');
// set foo to cache with a value of bar;
// foo will be cleared from cache after 5 seconds.jsoc.set('foo','bar', {'ttl':'5000'});
- add(cacheItemName: String, CacheItemValue: Object, [{'ttl':'milliseconds'}]): Int
-
// Adds to the cache, only if item doesn't already exist.
// If method returns 1, all is well.
// Optional argument "ttl" = 'time to live' and will clear
// the given cache item after the specified number of milliseconds.// Optional arguments ('time to live' [ttl] at the moment) are
// passed as a JSON object; {"ttl":"5000"} for example.Example:
// create a JSOC instance.
jsoc = new JSOC();
// set foo to cache with a value of bar.
jsoc.add('foo','bar');
// set foo to cache with a value of bar;
// foo will be cleared from cache after 5 seconds.jsoc.add('foo','bar', {'ttl':'5000'});
- replace(cacheItemName: String, CacheItemValue: Object, [{'ttl':'milliseconds'}]): Int
-
// Sets item to cache only if the key already exists.
// If method returns 1, all is well.
// Optional argument "ttl" = 'time to live' and will clear
// the given cache item after the specified number of milliseconds.// Optional arguments ('time to live' [ttl] at the moment) are
// passed as a JSON object; {"ttl":"5000"} for example.Example:
// create a JSOC instance.
jsoc = new JSOC();
// replace foo in cache if it exists; foo value will be bar.
jsoc.replace('foo','bar');
// replace foo in cache if it exists; foo value will be bar;
// foo will be cleared from cache after 5 seconds.jsoc.replace('foo','bar', {'ttl':'5000'});
- get(cacheItemName: String): Object | undefined
-
// Returns the cached object for the given key if it exists.
Example:
// create a JSOC instance.
jsoc = new JSOC();
// Return the cached object containing foo.
jsoc.get('foo');
- getMulti(cacheItemNames: Array): Array
-
// Returns an array of cached objects for the given keys.
Example:
// create a JSOC instance.
jsoc = new JSOC();
// return an array of cached objects.
jsoc.getMulti(['foo1','foo2']);
- getType(type: String): Array
-
// Returns an array of cached objects for the given JavaScript object type.
Example:
// create a JSOC instance.
jsoc = new JSOC();
// return an array of cached objects containing Number types.
jsoc.getType('Number');
- remove(cacheItemName: String): Int
-
// Removes an item from the cache for a given key.
Example:
// create a JSOC instance.
jsoc = new JSOC();
// remove foo from cache.
jsoc.remove('foo');
- flush_all(): Int
-
// Removes all items from cache.
Example:
// create a JSOC instance.
jsoc = new JSOC();
// remove all items from cache.
jsoc.flush_all();