JSPM

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

Basic object cache with `get`, `set`, `del`, and `has` methods 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

Basic object cache with get, set, del, and has methods for node.js/javascript projects.

Install

Install with npm

$ npm i cache-base --save

Usage

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

// instantiate
var app = new Cache();

// set values
app.set('a', 'b');
app.set('c.d', 'e');

// get values
app.get('a');
//=> 'b'
app.get('c');
//=> {d: 'e'}

console.log(app.cache);
//=> {a: 'b'}

Inherit

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

function MyApp() {
  Cache.call(this);
}
util.inherits(MyApp, Cache);

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

Namespace

Define a custom property for storing values.

var Cache = require('cache-base').namespace('data');
var app = new Cache();
app.set('a', 'b');
console.log(app.data);
//=> {a: 'b'}

API

namespace

Create a Cache constructor that, when instantiated, will store values on the given prop.

Params

  • prop {String}: The property name to use for storing values.
  • returns {Function}: Returns a custom Cache constructor

Example

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

Cache

Create a new Cache. Internally the Cache constructor is created using the namespace function, with cache defined as the storage object.

Params

  • cache {Object}: Optionally pass an object to initialize with.

Example

var app = new Cache();

.set

Set property key with the given value.

Params

  • key {String}
  • value {any}
  • returns {Cache}: Returns the instance for chaining

Example

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

.get

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

Params

  • key {String}

Example

app.set('foo', 'bar');
app.get('foo');
//=> "bar"

.has

Return true if cache key is not undefined or null.

Params

  • key {String}

Example

app.set('foo', 'bar');
app.has('foo');
//=> true

.del

Delete one or more properties from the cache.

Params

  • keys {String|Array}

Example

app.del('foo');
// or
app.del(['foo', 'bar']);

.clear

Reset the entire cache to an empty object.

Example

app.clear();

.visit

Visit method, or map-visit method, over each property in val.

Params

  • method {String}: The name of the method to call.
  • val {Object|Array}: The object or array to iterate over.

Example

app.visit('set', {a: 'b'});
  • base-methods: Starter for creating a node.js application with a handful of common methods, like set, get,… more | homepage
  • get-value: Use property paths ( a.b.c) to get a nested value from an object. | homepage
  • has-value: Returns true if a value exists, false if empty. Works with deeply nested values using… more | homepage
  • option-cache: Simple API for managing options in JavaScript applications. | homepage
  • set-value: Create nested values and any intermediaries using dot notation ('a.b.c') paths. | homepage
  • unset-value: Delete nested properties from an object using dot notation. | homepage

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 © 2014-2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on November 23, 2015.