https://github.com/itbrig/rcache
Report issues: https://github.com/itbrig/rcache/issues
-
rcache is an active cache. It adds a layer between the application and the jQuery ajax interface, enabling you to reuse stored resources without consulting the server.
-
rcache is observable. The application can register callbacks that will fire when a resources is beeing updated or removed.
-
rcache supports RESTful applications. It handles the standard HTTP methods GET, PUT, POST and DELETE.
rcache has been tested with jQuery 1.7.1 using QUnit unit test in /test
Firefox 10, Chrome 16
Copyright (c) 2012 Hannes Forsgård Licensed under the WTFPL (http://sam.zoy.org/wtfpl/)
rcache transparently supports conditional requests. If the server sends ETag or Last-Modified headers these are automatically returned as If-Unmodified-Since and If-Match headers for PUT and DELETE requests and as If-Modified-Since and If-None-Match headers for GET requests.
rcache is not a general purpose caching proxy. As such it does not honor no-store, no-cache, must-revalidate or vary headers. This kind of caching should not be implemented in clients, but rather through a forward proxy.
Some short usage examples. Checkout package and open the documentation for better coverage.
var jqXHR = $.rcache.item('/url/to/item').get();
jqXHR.done(function(){
//Do something when data is ready
//even if data is read from cache
});
//Update an item using PUT
$.rcache.item('/url/to/item').put({data});
//Create a new item using POST
var jqXHR = $.rcache.item('/creator/resource').post({data});
jqXHR.done(function(){
//A new item will be created in cache if response includes
//a Content-Location or Location header.
});
//Delete an item using DELETE
$.rcache.item('/item/to/remove').del();
$.rcache.item('/url/to/item').onWrite(function(data, etag, modified, jqXHR){
//Fired when cache item is updated (by a get, put, post or write action)
//Params: reponse data, etag and last-modified headers, jqXHR object
});
$.rcache.item('/url/to/item').onRemove(function(data, etag, modified, jqXHR){
//Fired when cache item is removed (by a del or remove action)
//Params: reponse data, etag and last-modified headers, jqXHR object
});
//Send a conditional get request
//if the server responds with fresh data a write event is fired
$.rcache.item('/url/to/item').update();
//Send an unconditional get request, write event will always be fired
$.rcache.item('/url/to/item').forceGet();
//Call .update() on all items with autoUpdate = true
$.rcache.updateAll();