javascript, cache system, SessionStorage, LocalStorage
Cachejs is a library that will allow you to set up a private and powerful cache system in your javascript application.
Source can be loaded via bower or downloaded from this repo. If you don't use a module loader it will be added to window.Cache
# bower
$ bower install coka-cachejs
# yarn
$ yarn add coka-cachejs
If you want to try the sample codes below, just open your browser's console and enter them.
<script type="text/javascript" src="cache.min.js"></script>
<script>
var cache = new Cache.Memory(25, 300, 'default');
cache.onWrite(function(key, data){
console.log('An entry has been added to the cache with the key "' + key + '" : ');
console.log(data);
});
cache.onRead(function(key, data){
console.log('An entry was read in the cache with the key "' + key + '" : ');
console.log(data);
});
cache.write('cachejs', {foo: 'foo'});
if (cache.has('cachejs')) {
var data = cache.read('cachejs');
console.log(data);
}
</script>
require.config({
paths: {
cache: 'cache.min',
}
});
define(['cache'], function (Cache) {
var cache = new Cache.Memory(25, 300, 'default');
cache.onWrite(function(key, data){
console.log('An entry has been added to the cache with the key "' + key + '" : ');
console.log(data);
});
cache.onRead(function(key, data){
console.log('An entry was read in the cache with the key "' + key + '" : ');
console.log(data);
});
cache.write('cachejs', {foo: 'foo'});
if (cache.has('cachejs')) {
var data = cache.read('cachejs');
console.log(data);
}
});
For notes about latest changes please read CHANGELOG.
For the versions available, see the tags on this repository.
This library is under the MIT license. See the complete license in the library.