Client Side Caching Library
I looked for a post about this library on the hub, I didn’t find it and decided to write a little about it.
The library is called locache.js and allows you to cache JS strings, arrays, and objects. The highlight of the library is that you can cache as inside a user session, i.e. before rebooting the browser window, and beyond its limits, i.e. even after closing the browser, the cache will remain.
A couple of examples from the library site:
In addition, I will give a real example of using this library. Now I am working on a web-based interface that loads only once and then all the actions create only AJAX requests to the server to receive new data. The interface and its loadable modules have many settings that change quite rarely. I store such settings as static files with a string representation of JS objects. With each change, the file gets a unique name. Then these files are read by the interface using AJAX requests. To cache them by file name, I use this library.
I hope someone comes in handy just like me.
The library is called locache.js and allows you to cache JS strings, arrays, and objects. The highlight of the library is that you can cache as inside a user session, i.e. before rebooting the browser window, and beyond its limits, i.e. even after closing the browser, the cache will remain.
A couple of examples from the library site:
- // Set The Cache Lifetime
- var seconds = 60;
- // Write data to the cache and set the lifetime to 60 seconds
- locache.set ("key", {
- 'user': 1,
- 'books': ['a', 'b', 'c']
- }, seconds);
- // Get data from the cache
- locache.get ("key");
- // {'user': 1, 'books': ['a', 'b', 'c']}
- // Attention, the object is returned, not the string
- // Eden 60 seconds and again try to get data from the cache
- locache.get ("key");
- // null
- // If you want to save data only for the current session
- // use the following entry
- locache.session.set ("private", {
- 'likes': ['kittens', 'JavaScript']
- });
- // All other methods also work for writing .session
- locache.session.get ("private");
- // All data stored in the session will be lost
- // when the user closes the browser
In addition, I will give a real example of using this library. Now I am working on a web-based interface that loads only once and then all the actions create only AJAX requests to the server to receive new data. The interface and its loadable modules have many settings that change quite rarely. I store such settings as static files with a string representation of JS objects. With each change, the file gets a unique name. Then these files are read by the interface using AJAX requests. To cache them by file name, I use this library.
I hope someone comes in handy just like me.