Package Exports
- @ioki/node-ts-cache-storage-pg
- @ioki/node-ts-cache-storage-pg/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ioki/node-ts-cache-storage-pg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-ts-cache-storage-pg
Postgres storage module for node-ts-cache.
This module is driver-agnostic. It expects you to bring your own raw query method - something most of the postgres available drivers provide. The driver needs to support the question-mark notation for prepared statements.
yarn add @ioki/node-ts-cache @ioki/node-ts-cache-storage-pgIn this example, node-postgres (pg) is being used. You should to provide a table with the following columns:
* key: text
value: jsonbThe query function should return an array of objects: { key: string, value: CacheItem }[].
import { PgStorage } from "@ioki/node-ts-cache-storage-pg"
import { Cache, CacheContainer } from "@ioki/node-ts-cache"
import Client from "pg"
const client = new Client()
await client.connect()
const storage = new PgStorage(tableName, async (query) => (await new Client().query(query)).rows)
const userCache = new CacheContainer(storage)
class MyService {
@Cache(userCache, { ttl: 60 })
public async getUsers(): Promise<string[]> {
return ["Max", "User"]
}
}