You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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)
  2. > A cache for managing namespaced sub-caches
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install --save fragment-cache
  7. ```
  8. ## Usage
  9. ```js
  10. var Fragment = require('fragment-cache');
  11. var fragment = new Fragment();
  12. ```
  13. ## API
  14. ### [FragmentCache](index.js#L24)
  15. Create a new `FragmentCache` with an optional object to use for `caches`.
  16. **Example**
  17. ```js
  18. var fragment = new FragmentCache();
  19. ```
  20. **Params**
  21. * `cacheName` **{String}**
  22. * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance.
  23. ### [.cache](index.js#L49)
  24. Get cache `name` from the `fragment.caches` object. Creates a new `MapCache` if it doesn't already exist.
  25. **Example**
  26. ```js
  27. var cache = fragment.cache('files');
  28. console.log(fragment.caches.hasOwnProperty('files'));
  29. //=> true
  30. ```
  31. **Params**
  32. * `cacheName` **{String}**
  33. * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance.
  34. ### [.set](index.js#L67)
  35. Set a value for property `key` on cache `name`
  36. **Example**
  37. ```js
  38. fragment.set('files', 'somefile.js', new File({path: 'somefile.js'}));
  39. ```
  40. **Params**
  41. * `name` **{String}**
  42. * `key` **{String}**: Property name to set
  43. * `val` **{any}**: The value of `key`
  44. * `returns` **{Object}**: The cache instance for chaining
  45. ### [.has](index.js#L93)
  46. Returns true if a non-undefined value is set for `key` on fragment cache `name`.
  47. **Example**
  48. ```js
  49. var cache = fragment.cache('files');
  50. cache.set('somefile.js');
  51. console.log(cache.has('somefile.js'));
  52. //=> true
  53. console.log(cache.has('some-other-file.js'));
  54. //=> false
  55. ```
  56. **Params**
  57. * `name` **{String}**: Cache name
  58. * `key` **{String}**: Optionally specify a property to check for on cache `name`
  59. * `returns` **{Boolean}**
  60. ### [.get](index.js#L115)
  61. 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.
  62. **Example**
  63. ```js
  64. var Vinyl = require('vinyl');
  65. var cache = fragment.cache('files');
  66. cache.set('somefile.js', new Vinyl({path: 'somefile.js'}));
  67. console.log(cache.get('somefile.js'));
  68. //=> <File "somefile.js">
  69. ```
  70. **Params**
  71. * `name` **{String}**
  72. * `returns` **{Object}**: Returns cache `name`, or the value of `key` if specified
  73. ## About
  74. ### Related projects
  75. * [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`.")
  76. * [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.")
  77. ### Contributing
  78. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  79. ### Building docs
  80. _(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).)_
  81. To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
  82. ```sh
  83. $ npm install -g verb verb-generate-readme && verb
  84. ```
  85. ### Running tests
  86. Install dev dependencies:
  87. ```sh
  88. $ npm install -d && npm test
  89. ```
  90. ### Author
  91. **Jon Schlinkert**
  92. * [github/jonschlinkert](https://github.com/jonschlinkert)
  93. * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  94. ### License
  95. Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
  96. Released under the [MIT license](https://github.com/jonschlinkert/fragment-cache/blob/master/LICENSE).
  97. ***
  98. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 17, 2016._