jsCache is a fast and small JavaScript library used for caching at client side. It helps you to decrease your server load and increase your application performance by caching api for the time period you want. Not only api you can case every type of data w
npm install js-cache-factorysh
$ npm install js-cache-factory --save
`
* #### Installing via bower
`sh
$ bower install js-cache --save
`
* #### Download via cdn
`sh
Comming soon ...
`
Configuration
* #### Configure for cache obj
`javascript
var cacheObjOptions = {
disableCache : false,
maxAge : 246060*1000, // 24 Hours
removeOnExpire : true,
deleteOnExpire : false,
storageMode : "memory",
onExpireCallback : null, // will be available in upcoming version
recycleFrequency : null, // will be available in upcoming version
capacity : null // will be available in upcoming version
};
`
* #### Configure for key,value you store
`javascript
var cacheKeyOptions = {
disableCache : false,
maxAge : null,
removeOnExpire : true,
onExpireCallback : null, // will be available in upcoming version
recycleFrequency : null // will be available in upcoming version
};
`
Getting Started
* #### Include file in project
`html
`
* #### Create obj
`javascript
var cacheObj = jsCache.create("cacheObjName", cacheObjOptions);
`
* #### Cache anything you want in created obj
`javascript
cacheObj.put("key", "value", cacheKeyOptions);
`
* #### Get saved value anywhere in your project
`javascript
cacheObj.get("key");
`
That's all you need to do.
You can create multiple objects with different configuration & can store multiple key,values into it.
Usage in AngularJS
jsCache is very good alternative for $cacheFactory in AngularJS.
* #### cache in $http request
Instead of calling create method
`javascript
var cacheObj = jsCache.create("cacheObjName", cacheObjOptions);
`
You have to call
`javascript
var httpCacheObj = jsCache.createHttpCache("cacheObjName", cacheObjOptions);
`
and pass it to
`javascript
$http({
method: 'GET',
url: "url you provide",
params: obj,
cache : httpCacheObj(cacheKeyOptions)
})
`
That's all else angular will take care of saving & retriving data for http calls.
Except $http api cache procedure is same as mentioned in Getting Started guide.
Api Reference
Comming soon ...
Docs
Comming soon ...
Testing
Run
`sh
$ npm test
``