Giter VIP home page Giter VIP logo

microcache.js's Introduction

microcache.js is a micro library to handle in-memory cache (works in node+browser).

Install it

To install it on node

npm install microcache

To install the browser version, download it and include it like that

<script src="microcache.js"></script>   

API

To instanciate a cache, do the following. You can have as many instances you want.

var microcache = new MicroCache();

.get(key)

To get a cached asset which is in the cache. Each cached element has a unique key to identify it.

microcache.get('foo');

.set(key, value)

To set a element value in the cache.

microcache.set('foo', 'bar');

.contains(key)

To know if a given asset is currently in the cache.

microcache.contains('foo');

.values()

To return all the elements currently in the cache

microcache.values();

.getSet(key, value)

To get an element from the cache, if it isnt already present, store it then return it.

microcache.getSet(key, value);

If second parameter is a function, it is called only if the key isnt contained in the cache. Thus the value isn't instanciated without need.

microcache.getSet(key, function(){ return value });

FAQ

  • Q. what about plain var microcache = {} ? isnt this wrapper overengineering ?
  • A. i was thinking so too at first. but the syntax of a .getSet() without wrapper was too ugly for my taste :) var a = cache[key] = (cache[key] || value) from @floriancargoet

microcache.js's People

Contributors

jeromeetienne avatar

Watchers

Darnyte avatar

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.