{"_id":"abstract-cache","_rev":"3-09f44d57d261be3ff609b2349a8802f4","name":"abstract-cache","description":"An abstract object cache interface","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"abstract-cache","version":"1.0.0","description":"An abstract object cache interface","main":"index.js","scripts":{"test":"tap 'test/**/*.test.js'","test-ci":"tap --cov 'test/**/*.test.js'","lint":"standard | snazzy","lint-ci":"standard"},"precommit":["lint","test"],"repository":{"type":"git","url":"git+ssh://git@github.com/jsumners/abstract-cache.git"},"keywords":["cache","generic","adapter"],"author":{"name":"James Sumners","email":"james.sumners@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/jsumners/abstract-cache/issues"},"homepage":"https://github.com/jsumners/abstract-cache#readme","devDependencies":{"mock-require":"^2.0.2","pre-commit":"^1.2.2","snazzy":"^7.0.0","standard":"^10.0.3","tap":"^10.7.3"},"dependencies":{"clone":"^2.1.1","lru_map":"^0.3.3","merge-options":"^1.0.0"},"gitHead":"aef9051eadf803aaacd5d90399288aaa288e1d37","_id":"abstract-cache@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"jsumners","email":"james.sumners@gmail.com"},"dist":{"integrity":"sha512-GgncxRUsvPm8gCHEoROvSrJMpCYxUbnraUTYqKchpRrYAywQ2Tmghefy4UFpBDbc7sCAmcCas6+iiU0DKjfPyg==","shasum":"51ad0ab5eb342ac839331e293bb855abfa51771e","tarball":"https://registry.npmjs.org/abstract-cache/-/abstract-cache-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHHa5yyZ3cHbtUF2qmBkh7+jk6FdPhPrbA0O8tR25IefAiEA9Lyv4ffntO7hgf54cbhsKqqsTT+IDGGrvwpFKkrwSvc="}]},"maintainers":[{"name":"jsumners","email":"james.sumners@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/abstract-cache-1.0.0.tgz_1511556547996_0.5228624267037958"},"directories":{}},"1.0.1":{"name":"abstract-cache","version":"1.0.1","description":"An abstract object cache interface","main":"index.js","scripts":{"test":"tap 'test/**/*.test.js'","test-ci":"tap --cov 'test/**/*.test.js'","lint":"standard | snazzy","lint-ci":"standard"},"precommit":["lint","test"],"repository":{"type":"git","url":"git+ssh://git@github.com/jsumners/abstract-cache.git"},"keywords":["cache","generic","adapter"],"author":{"name":"James Sumners","email":"james.sumners@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/jsumners/abstract-cache/issues"},"homepage":"https://github.com/jsumners/abstract-cache#readme","devDependencies":{"mock-require":"^3.0.1","pre-commit":"^1.2.2","snazzy":"^7.0.0","standard":"^11.0.0","tap":"^11.1.1"},"dependencies":{"clone":"^2.1.1","lru_map":"^0.3.3","merge-options":"^1.0.0"},"gitHead":"7f712d4e7573db6022379e85ce85f944e2720e6f","_id":"abstract-cache@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"jsumners","email":"james.sumners@gmail.com"},"dist":{"integrity":"sha512-EfUeMhRUbG5bVVbrSY/ogLlFXoyfMAPxMlSP7wrEqH53d+59r2foVy9a5KjmprLKFLOfPQCNKEfpBN/nQ76chw==","shasum":"136151becf5c32e0ea27f78728d073d8fe07932a","tarball":"https://registry.npmjs.org/abstract-cache/-/abstract-cache-1.0.1.tgz","fileCount":13,"unpackedSize":22619,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAPy+Oyy8e0YthU5QzSsPyVsSRtUDlvN8WPcJZSaYt6UAiAq7v1Q2XU2rEIbvxAHPYZv71hwxa0jQ5zDV9sASV0coA=="}]},"maintainers":[{"name":"jsumners","email":"james.sumners@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/abstract-cache_1.0.1_1519678449623_0.42134264702735935"},"_hasShrinkwrap":false}},"readme":"# abstract-cache\n\n*abstract-cache* is a module that provides a common interface to multiple\ncaching strategies. It allows for requiring *abstract-cache* everywhere while\ndefining the strategy via a simple configuration.\n\n*abstract-cache* is heavily inspired by the excellent [Catbox][catbox]. The\ndecision to create *abstract-cache* was predicated on a desire to require\nimplementing clients accept previously established connections in addtion to\naccepting configuration to create their own connections. It also seeks to\nallow using either the callback or async/await style of asynchronous\nprogramming.\n\n[catbox]: https://npm.im/catbox\n\n### Available Clients\n\n+ [abstract-cache-mongo](https://github.com/jsumners/abstract-cache-mongo)\n+ [abstract-cache-redis](https://github.com/jsumners/abstract-cache-redis)\n\n## Example\n\nThe following example uses *abstract-cache*'s included in-memory cache. Of note,\nis that the included in-memory cache is actually callback based.\n\n```js\nconst cache = requre('abstract-cache')({useAwait: true})\n\nasync function doSomething () {\n  const val = await cache.get('foo')\n  console.log(val)\n}\n\ncache.set('foo', 'foo', 100)\n  .then(doSomething)\n  .catch(console.error)\n```\n\nThis example shows instantiating *abstract-cache* with a specific store that\nrelies upon a connection to a remote system. In this example we are supplying\nan already existing connection to the remote system; all *abstract-cache*\ncompliant clients **must** support this.\n\n```js\nconst cache = require('abstract-cache')({\n  useAwait: true,\n  driver: {\n    name: 'abstract-cache-redis',\n    options: {\n      client: require('redis')({url: 'some.redis.url'})\n    }\n  }\n})\n\nasync function doSomething () {\n  const val = await cache.get('foo')\n  console.log(val)\n}\n\ncache.set('foo', 'foo', 100)\n  .then(doSomething)\n  .catch(console.error)\n```\n\n## Options\n\n*abstract-client* accepts an options object with the following properties:\n\n+ `useAwait` (Default: `false`): designate that the resulting cache client\nshould use `async/await` functions. When `false`, every method accepts a\nstandard `callback(err, result)`.\n+ `client` (Default: `undefined`): an already instantiated strategy client.\nIn combination with `useAwait` the client can be wrapped accordingly. Specifying\na `client` superceeds the `driver` configuration.\n+ `driver`:\n    * `name` (Default: `undefined`): specifies the implementing strategy to\n    load. The default value results in the buil-in in-memory strategy being\n    loaded -- this is **not recommended** for production environments.\n    * `options` (Default: `{}`): an options object to pass to the strategy\n    while loading. The strategy should describe this object.\n\n### memclient\n\nThe included in-memory client is available as:\n\n```js\nconst memclientFactory = require('abstract-cache').memclient\n```\n\nIt accepts an options object:\n\n+ `segment` (Default: `abstractMemcache`): the default segment in which to store\nitems.\n+ `maxItems` (Default: `100000`): the maximum number of items to keep in the\ncache. The backing is an LRU cache with an upper bound.\n\n## Protocol\n\nAll implementing strategies **must** implement the protocol described in this\nsection.\n\n1. The module should export a factory `function (optionsObject) {}`.\n1. Accept an existing connection to data stores via the `optionsObject`.\n1. Manage connections created by itself.\n1. In all cases where a `key` is required, the `key` may be a simple string,\nor it may be an object of the format `{id: 'name', segment: 'name'}`. It is\nup to the implementing strategy to decide how to handle these keys.\n1. The factory function should return an object (client) that has the following\nmethods and properties:\n    * `await` (boolean property): `true` indicates that the strategy's methods\n    are *all* `async` functions. If `false`, all methods **must** have a\n    `callback(err, result)` as the last parameter.\n    * `delete(key[, callback])`: removes the specified item from the cache.\n    * `get(key[, callback])`: retrieves the desired item from the cache. The\n    returned item should be a deep copy of the stored value to prevent alterations\n    from affecting the cache. The result should be an object with the properties:\n        + `item`: the item the user cached.\n        + `stored`: a `Date`, in Epoch milliseconds, indicating when the item\n        was stored.\n        + `ttl`: the *remaining* lifetime of the item in the cache (milliseconds).\n    * `has(key[, callback])`: returns a boolean result indicating if the cache\n    contains the desired `key`.\n    * `set(key, value, ttl[, callback])`: stores the specified `value` in the\n    cache under the specified `key` for the time `ttl` in milliseconds.\n    * `start([callback])` (optional): clients that require extra initialization,\n    e.g. to start a database connection, may export this method. When present,\n    this method **must** be invoked by the user before any other method. This\n    method may be an `async` function at the discretion of the implementor.\n    * `stop([callback])` (optional): required when `start()` is present. This\n    should shutdown any connections/processes started via `start()`. It is\n    left to the user to invoke this method in their shutdown procedure. This\n    method may be an `async` function at the discretion of the implementor.\n\n## License\n\n[MIT License](http://jsumners.mit-license.org/)\n\n","maintainers":[{"name":"jsumners","email":"james.sumners@gmail.com"}],"time":{"modified":"2022-04-11T12:26:35.282Z","created":"2017-11-24T20:49:08.890Z","1.0.0":"2017-11-24T20:49:08.890Z","1.0.1":"2018-02-26T20:54:09.674Z"},"homepage":"https://github.com/jsumners/abstract-cache#readme","keywords":["cache","generic","adapter"],"repository":{"type":"git","url":"git+ssh://git@github.com/jsumners/abstract-cache.git"},"author":{"name":"James Sumners","email":"james.sumners@gmail.com"},"bugs":{"url":"https://github.com/jsumners/abstract-cache/issues"},"license":"MIT","readmeFilename":"Readme.md"}