ds-cache
Simple data storage for cache
Last updated 4 years ago by dz1984 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ds-cache 
SYNC missed versions from official npm registry.

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)

Current Tags

  • 0.0.8                                ...           latest (4 years ago)

7 Versions

  • 0.0.8                                ...           4 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (1)

Copyright 2014 - 2017 © taobao.org |