Skip to content

Little cache lib using localStorage and promises

License

Notifications You must be signed in to change notification settings

Drulac/cache.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

cache.js

Little cache lib using localStorage and promises.

You just have to include cache.js :

<script type="text/javascript" src="https://drulac.github.io/cache.js/cache.js"></script>

How to use

Create a cache object :

let cache = new Cache();

Add a custom method using cache.newMethod(methodName, promise, validTimeInSecond) :

cache.newMethod("methodName", (arg1, arg2)=>{
	return new Promise((resolve, reject)=>{
		
		//work
		let result = arg1 + arg2;
		
		resolve(result);
	});
}, 10); //valid time in seconds

then you can call your custom method like a normal method :

cache.methodName();

That will return a promise. The data is automaticaly updated when she have expirate.

About

Little cache lib using localStorage and promises

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published