UNPKG

@makerx/node-cache

Version:

A NodeJS package that makes it easy to cache objects and files locally and in AWS

44 lines 2.67 kB
import { S3Client } from '@aws-sdk/client-s3'; import { BinaryCacheOptions, BinaryWithMetadata, CacheOptions, ObjectCache } from './cache'; /** Caches object/file data using AWS S3. */ export declare class S3ObjectCache implements ObjectCache { private s3Client; private bucket; private keyPrefix?; /** * Create an `S3ObjectCache` * @param s3Client An S3 client * @param bucket The name of the bucket to cache in * @param keyPrefix Optional prefix key to use for all cache entries; allows multiple caches to reside on a single S3 Bucket */ constructor(s3Client: S3Client, bucket: string, keyPrefix?: string); /** * Clear the cache value for te given cache key * @param cacheKey A unique key that identifies the cached value */ clearCache(cacheKey: string): Promise<void>; /** Adds the given value to the cache for the given cache key * @param cacheKey A unique key that identifies the cached value * @param data The data to cache * @param mimeType Optional mime type of the data; default = `application/json` or `application/octet-stream` depending on if the data is binary or JSON. */ put<T>(cacheKey: string, data: T, mimeType?: string): Promise<void>; /** Gets the cached value for the given cache key if it exists and * isn't expired, but otherwise gets the generated value while storing it in the cache * @param cacheKey A unique key that identifies the cached value * @param generator The async lambda that generates a "fresh" value when there is a cache miss * @param options Options to control the cache semantics **/ getAndCache<T>(cacheKey: string, generator: (existing: T | undefined) => Promise<T>, options?: CacheOptions): Promise<T>; /** Gets the cached value for the given cache key if it exists and * isn't expired, but otherwise gets the generated value while storing it in the cache; * expects binary data and returns the mime type as well as the data */ getAndCacheBinary(cacheKey: string, generator: (existing: Uint8Array | undefined) => Promise<Uint8Array>, options?: BinaryCacheOptions): Promise<BinaryWithMetadata>; /** Adds the given binary value to the cache for the given cache key * @param cacheKey A unique key that identifies the cached value * @param data The binary data to cache * @param mimeType Optional mime type of the data; default = `application/json` or `application/octet-stream` depending on if the data is binary or JSON. */ putBinary(cacheKey: string, data: Uint8Array, mimeType?: string): Promise<void>; } //# sourceMappingURL=s3ObjectCache.d.ts.map