@zkochan/pnpm
Version:
Fast, disk space efficient package manager
116 lines (115 loc) • 12.1 kB
JSON
{
"_args": [
[
{
"raw": "keyv@3.0.0",
"scope": null,
"escapedName": "keyv",
"name": "keyv",
"rawSpec": "3.0.0",
"spec": "3.0.0",
"type": "version"
},
"/home/zkochan/src/pnpm/packages/pnpm/node_modules/cacheable-request"
]
],
"_from": "keyv@3.0.0",
"_id": "keyv@3.0.0",
"_inCache": true,
"_location": "/keyv",
"_nodeVersion": "8.5.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/keyv-3.0.0.tgz_1507037905372_0.20707569341175258"
},
"_npmUser": {
"name": "lukechilds",
"email": "lukechilds123@gmail.com"
},
"_npmVersion": "5.3.0",
"_phantomChildren": {},
"_requested": {
"raw": "keyv@3.0.0",
"scope": null,
"escapedName": "keyv",
"name": "keyv",
"rawSpec": "3.0.0",
"spec": "3.0.0",
"type": "version"
},
"_requiredBy": [
"/cacheable-request"
],
"_resolved": "https://registry.npmjs.org/keyv/-/keyv-3.0.0.tgz",
"_shasum": "44923ba39e68b12a7cec7df6c3268c031f2ef373",
"_shrinkwrap": null,
"_spec": "keyv@3.0.0",
"_where": "/home/zkochan/src/pnpm/packages/pnpm/node_modules/cacheable-request",
"author": {
"name": "Luke Childs",
"email": "lukechilds123@gmail.com",
"url": "http://lukechilds.co.uk"
},
"bugs": {
"url": "https://github.com/lukechilds/keyv/issues"
},
"dependencies": {
"json-buffer": "3.0.0"
},
"description": "Simple key-value storage with support for multiple backends",
"devDependencies": {
"@keyv/mongo": "*",
"@keyv/mysql": "*",
"@keyv/postgres": "*",
"@keyv/redis": "*",
"@keyv/sqlite": "*",
"@keyv/test-suite": "*",
"ava": "^0.22.0",
"coveralls": "^3.0.0",
"eslint-config-xo-lukechilds": "^1.0.0",
"nyc": "^11.0.3",
"this": "^1.0.2",
"timekeeper": "^2.0.0",
"xo": "^0.19.0"
},
"directories": {},
"dist": {
"integrity": "sha512-eguHnq22OE3uVoSYG0LVWNP+4ppamWr9+zWBe1bsNcovIMy6huUJFPgy4mGwCd/rnl3vOLGW1MTlu4c57CT1xA==",
"shasum": "44923ba39e68b12a7cec7df6c3268c031f2ef373",
"tarball": "https://registry.npmjs.org/keyv/-/keyv-3.0.0.tgz"
},
"gitHead": "33ae64413338c465999863ea5545c1ae20b54ddb",
"homepage": "https://github.com/lukechilds/keyv",
"keywords": [
"key",
"value",
"store",
"cache",
"ttl"
],
"license": "MIT",
"main": "src/index.js",
"maintainers": [
{
"name": "lukechilds",
"email": "lukechilds123@gmail.com"
}
],
"name": "keyv",
"optionalDependencies": {},
"readme": "<h1 align=\"center\">\n\t<img width=\"250\" src=\"https://rawgit.com/lukechilds/keyv/master/media/logo.svg\" alt=\"keyv\">\n\t<br>\n\t<br>\n</h1>\n\n> Simple key-value storage with support for multiple backends\n\n[](https://travis-ci.org/lukechilds/keyv)\n[](https://coveralls.io/github/lukechilds/keyv?branch=master)\n[](https://www.npmjs.com/package/keyv)\n\nKeyv provides a consistent interface for key-value storage across multiple backends via storage adapters. It supports TTL based expiry, making it suitable as a cache or a persistent key-value store.\n\n## Features\n\nThere are a few existing modules similar to Keyv, however Keyv is different because it:\n\n- Isn't bloated\n- Has a simple Promise based API\n- Suitable as a TTL based cache or persistent key-value store\n- [Easily embeddable](#add-cache-support-to-your-module) inside another module\n- Works with any storage that implements the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) API\n- Handles all JavaScript types (values can be `Buffer`/`null`/`undefined`)\n- Supports namespaces\n- Wide range of [**efficient, well tested**](#official-storage-adapters) storage adapters\n- Connection errors are passed through (db failures won't kill your app)\n- Supports the current active LTS version of Node.js or higher\n\n## Usage\n\nInstall Keyv.\n\n```\nnpm install --save keyv\n```\n\nBy default everything is stored in memory, you can optionally also install a storage adapter.\n\n```\nnpm install --save @keyv/redis\nnpm install --save @keyv/mongo\nnpm install --save @keyv/sqlite\nnpm install --save @keyv/postgres\nnpm install --save @keyv/mysql\n```\n\nCreate a new Keyv instance, passing your connection string if applicable. Keyv will automatically load the correct storage adapter.\n\n```js\nconst Keyv = require('keyv');\n\n// One of the following\nconst keyv = new Keyv();\nconst keyv = new Keyv('redis://user:pass@localhost:6379');\nconst keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname');\nconst keyv = new Keyv('sqlite://path/to/database.sqlite');\nconst keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname');\nconst keyv = new Keyv('mysql://user:pass@localhost:3306/dbname');\n\n// Handle DB connection errors\nkeyv.on('error' err => console.log('Connection Error', err));\n\nawait keyv.set('foo', 'expires in 1 second', 1000); // true\nawait keyv.set('foo', 'never expires'); // true\nawait keyv.get('foo'); // 'never expires'\nawait keyv.delete('foo'); // true\nawait keyv.clear(); // undefined\n```\n\n### Namespaces\n\nYou can namespace your Keyv instance to avoid key collisions and allow you to clear only a certain namespace while using the same database.\n\n```js\nconst users = new Keyv('redis://user:pass@localhost:6379', { namespace: 'users' });\nconst cache = new Keyv('redis://user:pass@localhost:6379', { namespace: 'cache' });\n\nawait users.set('foo', 'users'); // true\nawait cache.set('foo', 'cache'); // true\nawait users.get('foo'); // 'users'\nawait cache.get('foo'); // 'cache'\nawait users.clear(); // undefined\nawait users.get('foo'); // undefined\nawait cache.get('foo'); // 'cache'\n```\n\n## Official Storage Adapters\n\nThe official storage adapters are covered by [over 150 integration tests](https://travis-ci.org/lukechilds/keyv/jobs/260418145) to guarantee consistent behaviour. They are lightweight, efficient wrappers over the DB clients making use of indexes and native TTLs where available.\n\nDatabase | Adapter | Native TTL | Status\n---|---|---|---\nRedis | [@keyv/redis](https://github.com/lukechilds/keyv-redis) | Yes | [](https://travis-ci.org/lukechilds/keyv-redis) [](https://coveralls.io/github/lukechilds/keyv-redis?branch=master)\nMongoDB | [@keyv/mongo](https://github.com/lukechilds/keyv-mongo) | Yes | [](https://travis-ci.org/lukechilds/keyv-mongo) [](https://coveralls.io/github/lukechilds/keyv-mongo?branch=master)\nSQLite | [@keyv/sqlite](https://github.com/lukechilds/keyv-sqlite) | No | [](https://travis-ci.org/lukechilds/keyv-sqlite) [](https://coveralls.io/github/lukechilds/keyv-sqlite?branch=master)\nPostgreSQL | [@keyv/postgres](https://github.com/lukechilds/keyv-postgres) | No | [](https://travis-ci.org/lukechildskeyv-postgreskeyv) [](https://coveralls.io/github/lukechilds/keyv-postgres?branch=master)\nMySQL | [@keyv/mysql](https://github.com/lukechilds/keyv-mysql) | No | [](https://travis-ci.org/lukechilds/keyv-mysql) [](https://coveralls.io/github/lukechilds/keyv-mysql?branch=master)\n\n## Third-party Storage Adapters\n\nYou can also use third-party storage adapters or build your own. Keyv will wrap these storage adapters in TTL functionality and handle complex types internally.\n\n```js\nconst Keyv = require('keyv');\nconst myAdapter = require('./my-storage-adapter');\n\nconst keyv = new Keyv({ store: myAdapter });\n```\n\nAny store that follows the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) api will work.\n\n```js\nnew Keyv({ store: new Map() });\n```\n\nFor example, [`quick-lru`](https://github.com/sindresorhus/quick-lru) is a completely unrelated module that implements the Map API.\n\n```js\nconst Keyv = require('keyv');\nconst QuickLRU = require('quick-lru');\n\nconst lru = new QuickLRU({ maxSize: 1000 });\nconst keyv = new Keyv({ store: lru });\n```\n\n## Add Cache Support to your Module\n\nKeyv is designed to be easily embedded into other modules to add cache support. The recommended pattern is to expose a `cache` option in your modules options which is passed through to Keyv. Caching will work in memory by default and users have the option to also install a Keyv storage adapter and pass in a connection string, or any other storage that implements the `Map` API.\n\nYou should also set a namespace for your module so you can safely call `.clear()` without clearing unrelated app data.\n\nInside your module:\n\n```js\nclass AwesomeModule {\n\tconstructor(opts) {\n\t\tthis.cache = new Keyv({\n\t\t\turi: typeof opts.cache === 'string' && opts.cache,\n\t\t\tstore: typeof opts.cache !== 'string' && opts.cache,\n\t\t\tnamespace: 'awesome-module'\n\t\t});\n\t}\n}\n```\n\nNow it can be consumed like this:\n\n```js\nconst AwesomeModule = require('awesome-module');\n\n// Caches stuff in memory by default\nconst awesomeModule = new AwesomeModule();\n\n// After npm install --save keyv-redis\nconst awesomeModule = new AwesomeModule({ cache: 'redis://localhost' });\n\n// Some third-party module that implements the Map API\nconst awesomeModule = new AwesomeModule({ cache: some3rdPartyStore });\n```\n\n## API\n\n### new Keyv([uri], [options])\n\nReturns a new Keyv instance.\n\nThe Keyv instance is also an `EventEmitter` that will emit an `'error'` event if the storage adapter connection fails.\n\n### uri\n\nType: `String`<br>\nDefault: `undefined`\n\nThe connection string URI.\n\nMerged into the options object as options.uri.\n\n### options\n\nType: `Object`\n\nThe options object is also passed through to the storage adapter. Check your storage adapter docs for any extra options.\n\n#### options.namespace\n\nType: `String`<br>\nDefault: `'keyv'`\n\nNamespace for the current instance.\n\n#### options.ttl\n\nType: `Number`<br>\nDefault: `undefined`\n\nDefault TTL. Can be overridden by specififying a TTL on `.set()`.\n\n#### options.store\n\nType: `Storage adapter instance`<br>\nDefault: `new Map()`\n\nThe storage adapter instance to be used by Keyv.\n\n#### options.adapter\n\nType: `String`<br>\nDefault: `undefined`\n\nSpecify an adapter to use. e.g `'redis'` or `'mongodb'`.\n\n### Instance\n\nKeys must always be strings. Values can be of any type.\n\n#### .set(key, value, [ttl])\n\nSet a value.\n\nBy default keys are persistent. You can set an expiry TTL in milliseconds.\n\nReturns `true`.\n\n#### .get(key)\n\nReturns the value.\n\n#### .delete(key)\n\nDeletes an entry.\n\nReturns `true` if the key existed, `false` if not.\n\n#### .clear()\n\nDelete all entries in the current namespace.\n\nReturns `undefined`.\n\n## License\n\nMIT © Luke Childs\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/lukechilds/keyv.git"
},
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test": "xo && nyc ava test/keyv.js",
"test:full": "xo && nyc ava --serial"
},
"version": "3.0.0",
"xo": {
"extends": "xo-lukechilds"
}
}