dc

ds-cache

Simple data storage for cache

Showing:

Popularity

Downloads/wk

4.7K

GitHub Stars

1

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

2

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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)

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial