Giter VIP home page Giter VIP logo

typeorm-nestjs-keyv-cache's Introduction

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

typeorm-nestjs-keyv-cache's People

Contributors

justinherter avatar acathur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.