Giter Club home page Giter Club logo

ds-cache's Introduction

ds-cache Build Status NPM

Provide a tool that is simple data storage as cache and easy to use.

The feature includes:

  • File size as Cache size.
  • Implement the LRU algorithm.

Documents

Generate the document.

$ codo lib/cache.coffee

Or you can go to CoffeeDoc.info watch this doc.

Installation

$ npm i ds-cache

API

  • Cache(option) - Constructor.

    • option.limit_bytes: limit the cache file size. Default: '100K'
    • option.auto_save: enable auto save cache. Default: false
    • option.filename: full name of save file. Default: 'ds_cache.json'
  • set(key, value) - Put data into cache.

    • key: the key of data.
    • val: the value of data.
  • get(key) - Catch data via key.

    • key: the key that you want to catch the data.
  • clear([key]) - Remove the data via key. Clear all data in the cache if you invoke this method without any arguments

    • key: optional. You could remove the data by key, either remove all data without any arguments.
  • save() - Write the cache into the file.

  • load() - Load the cache from file.

  • size() - Return the number of data in the cache.

  • content() - Return the JSON string of cache.

Examples

var Cache = require("ds-cache");

// initial the cache instance
var cache = new Cache(
    {
        limit_bytes: '2M',  // limit file size
        auto_save:  true,
        filename: 'ds_cache.json'
    }
);

// add a data
cache.set('name', 'Donald');

// get value via key
cache.get('name');

// clear data via key
cache.clear('name');

// clear all data
cache.clear();

License

The MIT License (MIT)

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.