{"_id":"@apollo/utils.keyvaluecache","_rev":"2908344","name":"@apollo/utils.keyvaluecache","description":"Minimal key-value cache interface","dist-tags":{"latest":"2.1.0"},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"time":{"modified":"2023-01-13T06:23:41.000Z","created":"2022-05-27T18:16:33.617Z","2.1.0":"2022-12-09T21:11:00.504Z","1.0.2":"2022-11-23T17:56:12.793Z","2.0.1":"2022-11-23T17:50:34.757Z","2.0.0":"2022-11-18T17:12:28.021Z","1.0.1":"2022-05-27T20:51:41.500Z","1.0.0":"2022-05-27T18:16:33.617Z"},"users":{},"author":{"name":"Apollo","email":"packages@apollographql.com"},"repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"versions":{"2.1.0":{"name":"@apollo/utils.keyvaluecache","version":"2.1.0","description":"Minimal key-value cache interface","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"keywords":["apollo","graphql","typescript","node"],"author":{"name":"Apollo","email":"packages@apollographql.com"},"license":"MIT","engines":{"node":">=14"},"dependencies":{"@apollo/utils.logger":"^2.0.0","lru-cache":"^7.14.1"},"gitHead":"2125deddbbcf4a30a623ca0128b4ef53641eb8d4","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"homepage":"https://github.com/apollographql/apollo-utils#readme","_id":"@apollo/utils.keyvaluecache@2.1.0","_nodeVersion":"16.18.1","_npmVersion":"8.5.0","dist":{"shasum":"90b3d1ca7e0e97a51f6705743057b0e5b8902480","size":9329,"noattachment":false,"key":"/@apollo/utils.keyvaluecache/-/@apollo/utils.keyvaluecache-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@apollo/utils.keyvaluecache/download/@apollo/utils.keyvaluecache-2.1.0.tgz"},"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils.keyvaluecache_2.1.0_1670620260342_0.4562100556875952"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-12-09T21:24:59.960Z","publish_time":1670620260504,"_cnpm_publish_time":1670620260504},"1.0.2":{"name":"@apollo/utils.keyvaluecache","version":"1.0.2","description":"Minimal key-value cache interface","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"keywords":["apollo","graphql","typescript","node"],"author":{"name":"Apollo","email":"packages@apollographql.com"},"license":"MIT","dependencies":{"@apollo/utils.logger":"^1.0.0","lru-cache":"7.10.1 - 7.13.1"},"gitHead":"42e59750f6712a41e6c2d8f1d6cba43cea9320a3","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"homepage":"https://github.com/apollographql/apollo-utils#readme","_id":"@apollo/utils.keyvaluecache@1.0.2","_nodeVersion":"16.18.0","_npmVersion":"8.5.0","dist":{"shasum":"2bfe358c4d82f3a0950518451996758c52613f57","size":7574,"noattachment":false,"key":"/@apollo/utils.keyvaluecache/-/@apollo/utils.keyvaluecache-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/@apollo/utils.keyvaluecache/download/@apollo/utils.keyvaluecache-1.0.2.tgz"},"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils.keyvaluecache_1.0.2_1669226172635_0.3315558438560169"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-11-23T18:03:47.015Z","publish_time":1669226172793,"_cnpm_publish_time":1669226172793},"2.0.1":{"name":"@apollo/utils.keyvaluecache","version":"2.0.1","description":"Minimal key-value cache interface","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"keywords":["apollo","graphql","typescript","node"],"author":{"name":"Apollo","email":"packages@apollographql.com"},"license":"MIT","engines":{"node":">=14"},"dependencies":{"@apollo/utils.logger":"^2.0.0","lru-cache":"^7.14.1"},"gitHead":"c5aaa55de1b163ef438ff57f9f65c600ec894d4d","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"homepage":"https://github.com/apollographql/apollo-utils#readme","_id":"@apollo/utils.keyvaluecache@2.0.1","_nodeVersion":"16.18.0","_npmVersion":"8.5.0","dist":{"shasum":"3c513d6201f6cb2b9ae84ec01d87707a9a4da842","size":7584,"noattachment":false,"key":"/@apollo/utils.keyvaluecache/-/@apollo/utils.keyvaluecache-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@apollo/utils.keyvaluecache/download/@apollo/utils.keyvaluecache-2.0.1.tgz"},"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils.keyvaluecache_2.0.1_1669225834551_0.7709928489668001"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-11-23T18:03:46.070Z","publish_time":1669225834757,"_cnpm_publish_time":1669225834757},"2.0.0":{"name":"@apollo/utils.keyvaluecache","version":"2.0.0","description":"Minimal key-value cache interface","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"keywords":["apollo","graphql","typescript","node"],"author":{"name":"Apollo","email":"packages@apollographql.com"},"license":"MIT","engines":{"node":">=14"},"dependencies":{"@apollo/utils.logger":"^2.0.0","lru-cache":"^7.10.1 - 7.13.1"},"gitHead":"a81b88047ea1213c08fec8530e6ab9c30d03ce59","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"homepage":"https://github.com/apollographql/apollo-utils#readme","_id":"@apollo/utils.keyvaluecache@2.0.0","_nodeVersion":"16.18.0","_npmVersion":"8.5.0","dist":{"shasum":"f99888f952792279e2be19426b0f7e3cf44f9472","size":7585,"noattachment":false,"key":"/@apollo/utils.keyvaluecache/-/@apollo/utils.keyvaluecache-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@apollo/utils.keyvaluecache/download/@apollo/utils.keyvaluecache-2.0.0.tgz"},"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils.keyvaluecache_2.0.0_1668791547848_0.6677232280295935"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-11-18T17:13:52.611Z","publish_time":1668791548021,"_cnpm_publish_time":1668791548021},"1.0.1":{"name":"@apollo/utils.keyvaluecache","version":"1.0.1","description":"Minimal key-value cache interface","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"keywords":["apollo","graphql","typescript","node"],"author":{"name":"Apollo","email":"packages@apollographql.com"},"license":"MIT","publishConfig":{"access":"public"},"dependencies":{"@apollo/utils.logger":"^1.0.0","lru-cache":"^7.10.1"},"gitHead":"6d472b801aa6368157109ef0f29490027fb0c6a3","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"homepage":"https://github.com/apollographql/apollo-utils#readme","_id":"@apollo/utils.keyvaluecache@1.0.1","_nodeVersion":"16.15.0","_npmVersion":"8.5.0","dist":{"shasum":"46f310f859067efe9fa126156c6954f8381080d2","size":7582,"noattachment":false,"key":"/@apollo/utils.keyvaluecache/-/@apollo/utils.keyvaluecache-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@apollo/utils.keyvaluecache/download/@apollo/utils.keyvaluecache-1.0.1.tgz"},"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils.keyvaluecache_1.0.1_1653684701313_0.04067822359641493"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-05-27T20:51:48.054Z","publish_time":1653684701500,"_cnpm_publish_time":1653684701500},"1.0.0":{"name":"@apollo/utils.keyvaluecache","version":"1.0.0","description":"Minimal key-value cache interface","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-utils.git","directory":"packages/keyValueCache/"},"keywords":["apollo","graphql","typescript","node"],"author":{"name":"Apollo","email":"packages@apollographql.com"},"license":"MIT","publishConfig":{"access":"public"},"dependencies":{"@apollo/utils.logger":"^1.0.0","lru-cache":"^7.10.1"},"gitHead":"b9149f9e637c8cb55866bb18c2366234f93e2406","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"homepage":"https://github.com/apollographql/apollo-utils#readme","_id":"@apollo/utils.keyvaluecache@1.0.0","_nodeVersion":"16.15.0","_npmVersion":"8.5.0","dist":{"shasum":"d5818cf7ddc9d3bec4e13f42ec88205601f45fad","size":7578,"noattachment":false,"key":"/@apollo/utils.keyvaluecache/-/@apollo/utils.keyvaluecache-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@apollo/utils.keyvaluecache/download/@apollo/utils.keyvaluecache-1.0.0.tgz"},"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"glasser","email":"glasser@apollographql.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils.keyvaluecache_1.0.0_1653675393460_0.2098874566029869"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-05-27T18:22:33.446Z","publish_time":1653675393617,"_cnpm_publish_time":1653675393617}},"readme":"# KeyValueCache interface\n\n```ts\nexport interface KeyValueCache<V = string> {\n  get(key: string): Promise<V | undefined>;\n  set(key: string, value: V, options?: KeyValueCacheSetOptions): Promise<void>;\n  delete(key: string): Promise<boolean | void>;\n}\n```\n\nThis interface defines a minimally-compatible cache intended for (but not limited to) use by Apollo Server. It is notably implemented by `KeyvAdapter` from the `@apollo/utils.keyvadapter` package. (`KeyvAdapter` in conjunction with a `Keyv` is probably more interesting to you unless you're actually building a cache!)\n\n# InMemoryLRUCache\n\nThis class wraps `lru-cache` and implements the `KeyValueCache` interface. It accepts `LRUCache.Options` as the constructor argument and passes them to the `LRUCache` which is created. A default `maxSize` and `sizeCalculator` are provided in order to prevent an unbounded cache; these can both be tweaked via the constructor argument.\n\n```ts\nconst cache = new InMemoryLRUCache({\n  // create a larger-than-default `LRUCache`\n  maxSize: Math.pow(2, 20) * 50,\n});\n```\n\n# PrefixingKeyValueCache\n\nThis class wraps a `KeyValueCache` in order to provide a specified prefix for keys entering the cache via this wrapper.\n\n```ts\nconst cache = new InMemoryLRUCache();\nconst prefixedCache = new PrefixingKeyValueCache(cache, \"apollo:\");\n```\n\nOne reason to use this is if a single piece of software wants to use a cache for multiple features. For example, you can pass a `KeyValueCache` as the `cache` option to `@apollo/server`'s `ApolloServer` class; it provides this cache to plugins and other features as a default cache to use (if the user does not provide the specific plugin its own cache). Each feature uses `PrefixingKeyValueCache` with a different prefix to prevent different features from stomping on each others' data.\n\nHowever, if you are configuring one of those features explicitly, you may _not_ want this prefix to be added. In that case, you can wrap your cache in a cache returned by `PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation`. The only difference between this cache and the cache that it wraps is that when it is passed directly to a `PrefixingKeyValueCache`, no prefix is applied.\n\nThat is, let's say you are using a class that is implemented like this:\n\n```ts\nclass SomePlugin {\n  private cache: KeyValueCache;\n  constructor(cache: KeyValueCache) {\n    this.cache = new PrefixingKeyValueCache(cache, \"some:\");\n  }\n}\n```\n\nIf you set up your plugin as `new SomePlugin({ cache: myRedisCache })` then the plugin will add `some:` to all keys when interacting with your cache, but if you set it up as `new SomePlugin({ cache: PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation(myRedisCache) })`, then the plugin will not apply its prefix. You should only do this if you feel confident that this feature's use of this cache will not overlap with another feature: perhaps this is the only feature you have configured to use this cache, or perhaps the feature provides suitable control over cache keys that you can ensure isolation without needing the plugin's prefix.\n\nSoftware like `ApolloServer` that passes a single `KeyValueCache` to several features should throw if a `PrefixesAreUnnecessaryForIsolationCache` is provided to it; it can check this condition with the static `PrefixingKeyValueCache.prefixesAreUnnecessaryForIsolation` method (which is safer than an `instanceof` check in case there are multiple copies of `@apollo/utils.keyvaluecache` installed).\n\n# ErrorsAreMissesCache\n\nThis class wraps a `KeyValueCache` in order to provide error tolerance for caches which connect via a client like Redis. In the event that there's an _error_, this wrapper will treat it as a cache miss (and log the error instead, if a `logger` is provided).\n\nAn example usage (which makes use of the `keyv` Redis client and our `KeyvAdapter`) would look something like this:\n\n```ts\nimport Keyv from \"keyv\";\nimport { KeyvAdapter } from \"@apollo/utils.keyvadapter\";\nimport { ErrorsAreMissesCache } from \"@apollo/utils.keyvaluecache\";\n\nconst redisCache = new Keyv(\"redis://user:pass@localhost:6379\");\nconst faultTolerantCache = new ErrorsAreMissesCache(\n  new KeyvAdapter(redisCache),\n);\n```\n","_attachments":{},"homepage":"https://github.com/apollographql/apollo-utils#readme","bugs":{"url":"https://github.com/apollographql/apollo-utils/issues"},"license":"MIT"}