JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19402440
  • Score
    100M100P100Q214959F

Basic, general purpose object cache for node.js/javascript projects.

Package Exports

  • cache-base

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cache-base) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cache-base NPM version

Basic, general purpose object cache for node.js/javascript projects.

Install

Install with npm

npm i cache-base --save

Usage

Create an instance:

var Cache = require('cache-base');
var cache = new Cache();

Inherit

var util = require('util');
var Cache = require('cache-base');

function App() {
  Cache.call(this);
}

util.inherits(App, Cache);

Example usage

var app = new App();

app.set('a', 'b');
app.get('a');
//=> 'b'

app.enable('abc');
console.log(app.enabled('abc'));
//=> 'true'

API

Cache

Create a new instance of Cache

  • cache {Object}: Optionally pass an object to initialize with.
var app = new Cache();

.set

Assign value to key or return the value of key.

  • key {String}
  • value {*}
  • returns {Cache}: for chaining
app.set(key, value);

// extend
app.set({a: 'b'});

.get

Return the stored value of key. If key is not defined, the cache is returned.

  • key {String}
app.set('foo', 'bar');
app.get('foo');
// => "bar"

.exists

Return true if the element exists. Dot notation may be used for nested properties.

  • key {String}
  • returns: {Boolean}

Example

app.exists('author.name');
//=> true

.extend

Extend the cache with the given object.

  • returns {Object} Cache: to enable chaining.

Example

app
  .extend({a: 'b'}, {c: 'd'});
  .extend('e', {f: 'g'});

.merge

Deep merge an object onto the cache.

  • returns {Object} Cache: to enable chaining.

Example

app.merge({a: {one: 'one'}}, {a: {two: 'two'}});
console.log(app.get('a'));
//=> {a: {one: 'one', two: 'two'}}

.forOwn

Return the keys on obj or this.cache.

  • obj {Object}: Optionally pass an object.
  • returns {Array}: Array of keys.
app.forOwn();

.keys

Return the keys on obj or this.cache.

  • obj {Object}: Optionally pass an object.
  • returns {Array}: Array of keys.
app.keys();

.functions

Return an object of only the properties on this.cache or the given obj that have function values.

  • obj {Object}
  • returns: {Array}
app.functions('foo')
//=> {set: [function], get: [function], functions: [function]}

.has

Return true if a deep property is on the given object or this.cache.

  • obj {Object}: Optionally pass an object.
  • returns {String} lookup: Prop string to use for the lookup, e.g. a.b
app.has('a.b.c');

.hasOwn

Return true if key is an own, enumerable property of this.cache or the given obj.

  • key {String}
  • obj {Object}: Optionally pass an object to check.
  • returns: {Boolean}
app.hasOwn(key);
// or
app.hasOwn(obj, key);

.clone

Clone the given obj or cache.

  • obj {Object}: Optionally pass an object to clone.
  • returns: {Boolean}
app.clone();

.omit

Delete a property or array of properties from the cache then re-save the cache.

  • key {String|Array}: The key(s) to omit from the cache
app.omit('foo');
// or
app.omit(['foo', 'bar']);

.clear

Remove key from the cache, or if no value is specified the entire cache is reset.

  • key {String}: The property to remove.

Example:

app.clear();

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on November 15, 2014.