Store data in memory for better performance by saving on network requests. (~600 bytes – minified and gzipped)
Using npm:
$ npm install js-memcache --save-dev
Using bower:
$ bower install js-memcache --save-dev
JSMemcache
is available via namespace JSMemcache
in browsers' global scope i.e.
<script src="path/to/JSMemcache.js"></script>
<script>
const jsMemcache = new JSMemcache(); // available via window.JSMemcache
...
</script>
JSMemcache
can be setup in node as following i.e.
const JSMemcache = require('JSMemcache');
const jsMemcache = new JSMemcache();
...
JSMemcache
can be setup as following using RequireJS i.e.
require(['path/to/JSMemcache'], function(JSMemcache) {
const jsMemcache = new JSMemcache();
...
});
JSMemcache exposes following API:
Set cache maximum limit. Default is set to 100 entries.
Set a key separator for each entry in cache. Default is +
.
Get cache's current limit.
Get cache's current separator.
Get cache's current size.
Add a new entry into cache as key value pair. Throws a TypeError
if key is neither a string
nor an array
.
Get an entry by key from cache.
Update an entry by key in cache. Throws a ReferenceError
if key does not exist in cache.
Remove an entry by key from cache. Throws a ReferenceError
if key does not exist in cache.
Get list of all entries in cache.
Get list of keys for all entries in cache.
Clear all data in cache and remove all entries.
An alias for .add()
An alias for .update()
If you find an issue or wish to suggest any improvements then use the issue tracker to file an issue. Please provide as much possible details in there. Even better that you can submit a pull request for your issue if you already have a solution in mind.
Contribution is most welcome. To cotribute, fork the repository and branch out from master
for your changes. Make sure you update/add tests. This repository uses the fantastic and super easy-to-use testing framework AVA. Once ready open a pull request.
MIT License © 2016 – Jabran Rafique