Skip to content

Commit

Permalink
keyv - removing awesome module content as it is in getting started gu…
Browse files Browse the repository at this point in the history
…ide (#1200)
  • Loading branch information
jaredwray authored Nov 12, 2024
1 parent 33273e6 commit f0475b7
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions packages/keyv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,41 +279,6 @@ The following are third-party storage adapters compatible with Keyv:
- [keyv-momento](https://github.com/momentohq/node-keyv-adaptor/) - Momento storage adapter for Keyv
- [@resolid/keyv-sqlite](https://github.com/huijiewei/keyv-sqlite) - A new SQLite storage adapter for Keyv

# Add Cache Support to your Module

Keyv 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.

You should also set a namespace for your module so you can safely call `.clear()` without clearing unrelated app data.

Inside your module:

```js
class AwesomeModule {
constructor(opts) {
this.cache = new Keyv({
uri: typeof opts.cache === 'string' && opts.cache,
store: typeof opts.cache !== 'string' && opts.cache,
namespace: 'awesome-module'
});
}
}
```

Now it can be consumed like this:

```js
import AwesomeModule from 'awesome-module';

// Caches stuff in memory by default
const awesomeModule = new AwesomeModule();

// After npm install --save keyv-redis
const awesomeModule = new AwesomeModule({ cache: 'redis://localhost' });

// Some third-party module that implements the Map API
const awesomeModule = new AwesomeModule({ cache: some3rdPartyStore });
```

# Compression

Keyv supports `gzip` and `brotli` compression. To enable compression, pass the `compress` option to the constructor.
Expand Down

0 comments on commit f0475b7

Please sign in to comment.