UNPKG

use-cache-helper

Version:

use-cache-helper provides helper functions to easily manage and scale your redis and database caching strategies.

56 lines (55 loc) 1.54 kB
/// <reference types="node" /> import { Redis } from 'ioredis'; import { Redis as UpstashRedis } from '@upstash/redis'; import type { Redis as UpstashRedis1 } from '@upstash/redis'; export interface IGetOrRefreshParams<T> { key: string; expiry?: number; forceRefresh?: boolean; parseResult?: boolean; cacheRefreshHandler?: () => Promise<T>; } export type IGetOrRefreshDataInPaginatedListParams<T> = IGetOrRefreshParams<T> & { id: string; listKey: string; updateScoreInPaginatedList?: number; key?: string; score?: number; }; export type IGetOrRefreshReturnValue<T> = Promise<T | undefined | null>; export interface ISetParams<T> { key: string; value: string | number | Buffer | Object | Record<string, string | T> | T; expiry?: number; } export interface IAppInitParams { maxPaginatedItems?: number; redis?: Redis; upstashRedis?: UpstashRedis | UpstashRedis1 | null; verbose?: boolean; } export interface IAppStoreRef { redis: Redis | null; maxPaginatedItems: number; upstashRedis: UpstashRedis | UpstashRedis1 | null; } export interface IGetPaginatedListByPageParams { key: string; page: number; sizePerPage: number; ascendingOrder?: boolean; } export interface IInsertPaginatedListItemParams { key: string; id: string; score?: number; } export interface IRemoveItemFromPaginatedListParams { key: string; id: string; } export interface IUpdateItemScoreFromPaginatedList { key: string; id: string; score: number; }