JAVASCRIPT CLIENT SIDE CACHING.



locache.js is a simple framework to help you cache objects on the client-side. It's not a replacement for HTTP caching, and often that is a better idea. Rather it allows you to cache JavaScript objects ( anything that is JSON serialisable) for re-use or offline usage. You can optionally provide an expiration time for cached objects.











Usage



var seconds = 60
 
locache.set("key", {
'user': 1,
'books': ['a', 'b', 'c']
}, seconds)
 
locache.get("key")
// {'user': 1, 'books': ['a', 'b', 'c']}
// Note the object is returned, not a string.
 
// Now wait, 60 seconds.
locache.get("key")
// null
 
// If you want to store a value only
// for the users session, use the following
locache.session.set("private", {
'likes': ['kittens', 'JavaScript']
})
 
// All the other methods work for the
// session cache too
locache.session.get("private")
 
// All values stored on the session cache will
// expire when the user closes the browser.

Documentation, code and test