JSPM

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

Generic 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 Build Status

Generic object cache for node.js/javascript projects.

Install with npm

npm i cache-base --save

Usage

Create an instance:

var App = require('cache-base');
var app = new App();

Inherit

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

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

util.inherits(App, App);

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}
app.exists('author.name');
//=> true

.extend

Extend the cache with the given object.

  • returns {Object} Cache: to enable chaining.
app
  .extend({a: 'b'}, {c: 'd'});
  .extend('e', {f: 'g'});

.merge

Deep merge an object onto the cache.

  • returns {Object} Cache: to enable chaining.
app.merge({a: {one: 'one'}}, {a: {two: 'two'}});
console.log(app.get('a'));
//=> {a: {one: 'one', two: 'two'}}

.pick

Extend the cache with only the specified values from the given object.

  • key {String|Array}: The key(s) to pick from the object and extend onto app.cache
var obj = {a: 'a', b: 'b', c: 'c'};
app.pick(obj, 'a');
//=> {a: 'a'}

app.pick(obj, ['a', 'b']);
//=> {a: 'a', b: 'b'}

.omit

Omit a property or array of properties from the cache

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

.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();

.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();
  • option-cache: Simple API for managing options in JavaScript applications.
  • config-cache: General purpose JavaScript object storage methods.
  • engine-cache: express.js inspired template-engine manager.
  • loader-cache: Register loader functions that dynamically read, parse or otherwise transform file contents when the name of the loader matches a file extension. You can also compose loaders from other loaders.
  • parser-cache: Cache and load parsers, similiar to consolidate.js engines.
  • helper-cache: Easily register and get helper functions to be passed to any template engine or node.js application. Methods for both sync and async helpers.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Running tests

Install dev dependencies.

npm i -d && npm test

Author

Jon Schlinkert

License

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


This file was generated by verb-cli on March 11, 2015.