I looked for a post on this library about Habré, did not find it, and decided to write a short story 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 within a user session, i.e. before the browser window is reloaded, or behind it, i.e. even after the browser is closed, the cache will remain.
A couple of examples from the library site: ')
// Set the cache lifetime
var seconds = 60 ;
// Write the data to the cache and set the lifetime to 60 seconds
locache. set ( "key" , {
'user' : 1 ,
'books' : [ 'a' , 'b' , 'c' ]
} , seconds ) ;
// Get the data from the cache
locache. get ( "key" ) ;
// {'user': 1, 'books': ['a', 'b', 'c']}
// Attention, it is the object that is returned, not the string
// Eden 60 seconds and again try to get the data from the cache
locache. get ( "key" ) ;
// null
// If you want to save data only for the current session
// need to 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 the use of this library. Now I’m working on a web interface that loads only once and then all actions create only AJAX requests to the server to get new data. The interface and its loadable modules have many settings that change quite rarely. Such settings I store as static files with a string representation of JS objects. With each change, the file gets a unique name. These files are then read by the interface using AJAX requests. To cache them by file name, I use this library.