DOMCached

Introduction | Download | Test | Documentation | Compatibility | Usage | Methods | To-do list

Introduction

DOMCached is a simple wrapper library for the use of DOM Storage provided by the modern browsers. The library is designed after the hugely popular memcached caching system, providing similar "caching" options in JavaScript in the form of local storage.

While the original DOM Storage provides only methods to save and read string values, DOMCached can input and output any JSON compatible objects. DOMCached includes also support for namespaces and data expiring.

DOMCached comes in two versions - as a module which requires Prototype (prototypejs.org) and in the for of a jQuery plugin. When using DOMCached as the jQuery plugin, then jquery-json plugin is also needed, since jQuery doesn't provide methods to decode/encode JSON strings.

© 2009 Andris Reinman, FlyCom - andris.reinman@gmail.com

NB! DOMCached development has been ceased in favor of jStorage http://www.jstorage.info

Download

DOMCached source is hosted at GitHub
Download from GitHub, source files (both for Prototype and jQuery) can be found at the "/src" directory.

DOMCached is licenced under a MIT-style licence.

Test

This is the Prototype version. To test the jQuery plugin, use this demo instead.

Saved values

Refresh the browser page or navigate away and back to see if the saved values survive the transition.

Add or replace element
Key:
Value:
NS:
Action:

or

Documentation

Compatibility

DOMCached can be used in any browser in the form that where it doesn't work no cache hits will ever occur.

BrowserStorage
support
Survives
browser
restart
Survives
browser
crash
Storage
size
Chrome 4 + + + 5 MB
Firefox 3.6 + + + 5 MB
Firefox 3 + + + 5 MB
Firefox 2 + + + 5 MB
IE8 + + + 10 MB
IE7 + + + 128 kB
IE6 + + + 128kB
Opera 10.5 + + - 5 MB
Opera 10.10 - N/A N/A N/A
Safari 4 + + + 5 MB
Safari 3 - N/A N/A N/A

Usage

With Prototype:

<script src="prototype.js"></script>
<script src="domcached.js"></script>
<script>
//Lets try to read some data from DOMCached
var value = DOMCached.get("key");
if(!value){
	//If there wasn't a cache hit, lets load the data from the server...
 	value = load_data_from_server()
 	// ...and try to set the cache for future requests
	DOMCached.set("key",value);
}
</script>

As the jQuery plugin:

<script src="jquery.js"></script>
<script src="jquery-json.js"></script>
<script src="domcached.js"></script>
<script>
//Lets try to read some data from DOMCached
var value = $.DOMCached.get("key");
if(!value){
	//If there wasn't a cache hit, lets load the data from the server...
 	value = load_data_from_server()
 	// ...and try to set the cache for future requests
	$.DOMCached.set("key",value);
}
</script>

Available methods

To-do list