Git Product home page Git Product logo

cache-lite's Introduction

NPM Badge

cache-lite CircleCI

Description

Simple node in-memory caching system

Download

The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm):

  npm install cache-lite

Example

const CacheLite = require('cache-lite');

const cache = new CacheLite()

// Set value in the cache for 200ms
cache.set("myKey", "myData", 200).then(() => {
})

// Get value from the cache
cache.get("myKey").then((value) => {
  console.log(value); // myData
})

cache.getKeys() // [ 'myKey' ]

cache.size() // 1

//Get value from the cache after 300ms
setTimeout(() => {
  cache.get("myKey").then((value) => {
  }).catch((err) => {
    // Error: The key myKey doesn't exist in the cache
  })
}, 300);

API

###set(key, value, ttl) Returns a promises

key

Type: string

Key

value

Type: string

Value

ttl (optional)

Type: number

Time to live

###get(key) Returns a promises

key

Type: string

Key

###getKeys() Returns keys stored in the cache

###size() Returns the number of elements in the cache

###clear() Delete all cached values from the cache

Requirement

Node >= 5.0

License

MIT © Thomas Blanc-Hector

cache-lite's People

Contributors

jsnomad avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

marslabtron

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.