1.1.3 • Published 1 year ago

typeorm-nestjs-keyv-cache v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Typeorm KeyV Cache

A typeorm cache provider based on keyv.

Installation

# npm
npm i typeorm-keyv-cache keyv --save

# or yarn
yarn add typeorm-keyv-cache keyv

General Usage

// optional parameters for Keyv
const options: Keyv.Options<any> = {
  /**
   * Namespace for the current instance,
   * also becomes the cache key prefix and defaults to 'cache'.
   */
  namespace?: string | undefined;
  /** A custom serialization function. */
  serialize?: ((data: DeserializedData<Value>) => string) | undefined;
  /** A custom deserialization function. */
  deserialize?: ((data: string) => DeserializedData<Value> | undefined) | undefined;
  /** The connection string URI. */
  uri?: string | undefined;
  /** The storage adapter instance to be used by Keyv. */
  store?: Store<string | undefined> | undefined;
  /** Default TTL. Can be overridden by specififying a TTL on `.set()`. */
  ttl?: number | undefined;
  /** Specify an adapter to use. e.g `'redis'` or `'mongodb'`. */
  adapter?: 'redis' | 'mongodb' | 'mongo' | 'sqlite' | 'postgresql' | 'postgres' | 'mysql' | undefined;
  /** Enable compression option **/
  compression?: CompressionAdapter | undefined;
}

// General In-memory Cache
import { CacheProvider } from 'typeorm-keyv-cache'

const cache = new CacheProvider(options);

// General In-memory Cache Injectable with NestJS
@Injectable()
class SomeClass {
  constructor(private readonly cache: CacheProvider){}
}



import { createConnection } from 'typeorm'
import { CacheProvider } from 'typeorm-keyv-cache'


// General In-memory Cache
createConnection({
  // ... db config
  cache: {
    provider() {
      return new CacheProvider()
    },
  },
})

// Redis
createConnection({
  // ... db config
  cache: {
    provider() {
      return new KeyvCacheProvider('redis://user:pass@localhost:6379')
    },
  },
})

// ...

For more examples, visit keyv documentation.

License

MIT

Copyright (c) 2023, Justin Herter

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago