Giter Site home page Giter Site logo

jabranr / js-memcache Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 45 KB

Store data in memory for better performance by saving on network requests.

Home Page: https://www.npmjs.com/package/js-memcache

License: MIT License

JavaScript 100.00%
javascript in-memory-storage cache requirejs nodejs

js-memcache's Introduction

JSMemcache Build Status npm version

Store data in memory for better performance by saving on network requests. (~600 bytes – minified and gzipped)

Installation

Using npm:

$ npm install js-memcache --save-dev

Using bower:

$ bower install js-memcache --save-dev

In browser:

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>

In node / Using CommonJS:

JSMemcache can be setup in node as following i.e.

const JSMemcache = require('JSMemcache');
const jsMemcache = new JSMemcache();
...

Using AMD (RequireJS):

JSMemcache can be setup as following using RequireJS i.e.

require(['path/to/JSMemcache'], function(JSMemcache) {
  const jsMemcache = new JSMemcache();
  ...
});

API

JSMemcache exposes following API:

.setLimit(limit {int})

Set cache maximum limit. Default is set to 100 entries.

.setSeparator(separator {string})

Set a key separator for each entry in cache. Default is +.

.getLimit()

Get cache's current limit.

.getSeparator()

Get cache's current separator.

.getSize()

Get cache's current size.

.add(key {string|array}, value {mixed})

Add a new entry into cache as key value pair. Throws a TypeError if key is neither a string nor an array.

.get(key {string|array})

Get an entry by key from cache.

.update(key {string|array}, value {mixed})

Update an entry by key in cache. Throws a ReferenceError if key does not exist in cache.

.remove(key {string|array})

Remove an entry by key from cache. Throws a ReferenceError if key does not exist in cache.

.all()

Get list of all entries in cache.

.keys()

Get list of keys for all entries in cache.

.clear()

Clear all data in cache and remove all entries.

.set(key {string|array}, value {mixed})

An alias for .add()

.replace(key {string|array}, value {mixed})

An alias for .update()

Issues / Contributing

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.

https://github.com/jabranr/js-memcache

License

MIT License © 2016 – Jabran Rafique

js-memcache's People

Contributors

jabranr avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

js-memcache's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.