1 # fragment-cache [![NPM version](https://img.shields.io/npm/v/fragment-cache.svg?style=flat)](https://www.npmjs.com/package/fragment-cache) [![NPM downloads](https://img.shields.io/npm/dm/fragment-cache.svg?style=flat)](https://npmjs.org/package/fragment-cache) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fragment-cache.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/fragment-cache)
3 > A cache for managing namespaced sub-caches
7 Install with [npm](https://www.npmjs.com/):
10 $ npm install --save fragment-cache
16 var Fragment = require('fragment-cache');
17 var fragment = new Fragment();
22 ### [FragmentCache](index.js#L24)
24 Create a new `FragmentCache` with an optional object to use for `caches`.
29 var fragment = new FragmentCache();
34 * `cacheName` **{String}**
35 * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance.
37 ### [.cache](index.js#L49)
39 Get cache `name` from the `fragment.caches` object. Creates a new `MapCache` if it doesn't already exist.
44 var cache = fragment.cache('files');
45 console.log(fragment.caches.hasOwnProperty('files'));
51 * `cacheName` **{String}**
52 * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance.
54 ### [.set](index.js#L67)
56 Set a value for property `key` on cache `name`
61 fragment.set('files', 'somefile.js', new File({path: 'somefile.js'}));
67 * `key` **{String}**: Property name to set
68 * `val` **{any}**: The value of `key`
69 * `returns` **{Object}**: The cache instance for chaining
71 ### [.has](index.js#L93)
73 Returns true if a non-undefined value is set for `key` on fragment cache `name`.
78 var cache = fragment.cache('files');
79 cache.set('somefile.js');
81 console.log(cache.has('somefile.js'));
84 console.log(cache.has('some-other-file.js'));
90 * `name` **{String}**: Cache name
91 * `key` **{String}**: Optionally specify a property to check for on cache `name`
92 * `returns` **{Boolean}**
94 ### [.get](index.js#L115)
96 Get `name`, or if specified, the value of `key`. Invokes the [cache](#cache) method, so that cache `name` will be created it doesn't already exist. If `key` is not passed, the entire cache (`name`) is returned.
101 var Vinyl = require('vinyl');
102 var cache = fragment.cache('files');
103 cache.set('somefile.js', new Vinyl({path: 'somefile.js'}));
104 console.log(cache.get('somefile.js'));
105 //=> <File "somefile.js">
110 * `name` **{String}**
111 * `returns` **{Object}**: Returns cache `name`, or the value of `key` if specified
117 * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.")
118 * [map-cache](https://www.npmjs.com/package/map-cache): Basic cache object for storing key-value pairs. | [homepage](https://github.com/jonschlinkert/map-cache "Basic cache object for storing key-value pairs.")
122 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
126 _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
128 To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
131 $ npm install -g verb verb-generate-readme && verb
136 Install dev dependencies:
139 $ npm install -d && npm test
146 * [github/jonschlinkert](https://github.com/jonschlinkert)
147 * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
151 Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
152 Released under the [MIT license](https://github.com/jonschlinkert/fragment-cache/blob/master/LICENSE).
156 _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 17, 2016._