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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # map-cache [![NPM version](https://img.shields.io/npm/v/map-cache.svg?style=flat)](https://www.npmjs.com/package/map-cache) [![NPM downloads](https://img.shields.io/npm/dm/map-cache.svg?style=flat)](https://npmjs.org/package/map-cache) [![Build Status](https://img.shields.io/travis/jonschlinkert/map-cache.svg?style=flat)](https://travis-ci.org/jonschlinkert/map-cache)
  2. Basic cache object for storing key-value pairs.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install map-cache --save
  7. ```
  8. Based on MapCache in Lo-dash v3.0. [MIT License](https://github.com/lodash/lodash/blob/master/LICENSE.txt)
  9. ## Usage
  10. ```js
  11. var MapCache = require('map-cache');
  12. var mapCache = new MapCache();
  13. ```
  14. ## API
  15. ### [MapCache](index.js#L28)
  16. Creates a cache object to store key/value pairs.
  17. **Example**
  18. ```js
  19. var cache = new MapCache();
  20. ```
  21. ### [.set](index.js#L45)
  22. Adds `value` to `key` on the cache.
  23. **Params**
  24. * `key` **{String}**: The key of the value to cache.
  25. * `value` **{any}**: The value to cache.
  26. * `returns` **{Object}**: Returns the `Cache` object for chaining.
  27. **Example**
  28. ```js
  29. cache.set('foo', 'bar');
  30. ```
  31. ### [.get](index.js#L65)
  32. Gets the cached value for `key`.
  33. **Params**
  34. * `key` **{String}**: The key of the value to get.
  35. * `returns` **{any}**: Returns the cached value.
  36. **Example**
  37. ```js
  38. cache.get('foo');
  39. //=> 'bar'
  40. ```
  41. ### [.has](index.js#L82)
  42. Checks if a cached value for `key` exists.
  43. **Params**
  44. * `key` **{String}**: The key of the entry to check.
  45. * `returns` **{Boolean}**: Returns `true` if an entry for `key` exists, else `false`.
  46. **Example**
  47. ```js
  48. cache.has('foo');
  49. //=> true
  50. ```
  51. ### [.del](index.js#L98)
  52. Removes `key` and its value from the cache.
  53. **Params**
  54. * `key` **{String}**: The key of the value to remove.
  55. * `returns` **{Boolean}**: Returns `true` if the entry was removed successfully, else `false`.
  56. **Example**
  57. ```js
  58. cache.del('foo');
  59. ```
  60. ## Related projects
  61. You might also be interested in these projects:
  62. * [cache-base](https://www.npmjs.com/package/cache-base): Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects. | [homepage](https://github.com/jonschlinkert/cache-base)
  63. * [config-cache](https://www.npmjs.com/package/config-cache): General purpose JavaScript object storage methods. | [homepage](https://github.com/jonschlinkert/config-cache)
  64. * [option-cache](https://www.npmjs.com/package/option-cache): Simple API for managing options in JavaScript applications. | [homepage](https://github.com/jonschlinkert/option-cache)
  65. ## Contributing
  66. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/map-cache/issues/new).
  67. ## Building docs
  68. Generate readme and API documentation with [verb](https://github.com/verbose/verb):
  69. ```sh
  70. $ npm install verb && npm run docs
  71. ```
  72. Or, if [verb](https://github.com/verbose/verb) is installed globally:
  73. ```sh
  74. $ verb
  75. ```
  76. ## Running tests
  77. Install dev dependencies:
  78. ```sh
  79. $ npm install -d && npm test
  80. ```
  81. ## Author
  82. **Jon Schlinkert**
  83. * [github/jonschlinkert](https://github.com/jonschlinkert)
  84. * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  85. ## License
  86. Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
  87. Released under the [MIT license](https://github.com/jonschlinkert/map-cache/blob/master/LICENSE).
  88. ***
  89. _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 10, 2016._