@melchyore/adonis-cache
Version:
Cache package for AdonisJS V5
54 lines (53 loc) • 2.74 kB
TypeScript
/// <reference types="@adonisjs/events/build/adonis-typings" />
import type { EmitterContract } from '@ioc:Adonis/Core/Event';
import type { CacheStoreContract, CacheConfig, CacheStoreConfig, AsyncFunction, RepositoryContract, PutManyResult, TaggedCacheContract, CacheStoresList } from '@ioc:Adonis/Addons/Cache';
/**
* Repository class that will call the appropriate
* store methods.
*
* @export
* @class Repository
* @implements {RepositoryContract<CacheStoreContract>}
*/
export default class Repository<Name extends keyof CacheStoresList> implements RepositoryContract<Name> {
protected _store: CacheStoreContract;
private prefix;
static readonly DEFAULT_TTL: number;
private _config;
private _driverConfig;
private event;
private emitter;
constructor(_store: CacheStoreContract, prefix: string);
get config(): CacheConfig;
get driverConfig(): CacheStoreConfig;
get getTTL(): number;
get store(): CacheStoreContract;
setConfig(config: CacheConfig, driverConfig: CacheStoreConfig): void;
setEventDispatcher(_emitter: EmitterContract): void;
get<T = any>(key: string, fallback?: T | AsyncFunction<T>): Promise<T | null>;
many<T extends Record<string, any>>(keys: Array<string>): Promise<T>;
has(key: string): Promise<boolean>;
missing(key: string): Promise<boolean>;
pull<T = any>(key: string): Promise<T | null>;
put<T = any>(key: string, value: T, ttl?: number | null): Promise<boolean>;
add<T = any>(key: string, value: T, ttl?: number | null): Promise<boolean>;
set<T = any>(key: string, value: T, ttl?: number | null): Promise<boolean>;
increment(key: string, value?: number): Promise<number | boolean>;
decrement(key: string, value?: number): Promise<number | boolean>;
putMany(list: Record<string, unknown>, ttl?: number): Promise<PutManyResult>;
putManyForever(list: Record<string, unknown>): Promise<PutManyResult>;
forever<T = any>(key: string, value: T): Promise<boolean>;
forget(key: string): Promise<boolean>;
forgetMultiple(keys: Array<string>): Promise<Record<string, boolean>>;
remember<T = any>(key: string, ttl: number | null, closure: AsyncFunction<T>): Promise<T | undefined>;
sear<T = any>(key: string, closure: AsyncFunction<T>): Promise<T | undefined>;
rememberForever<T = any>(key: string, closure: AsyncFunction<T>): Promise<T | undefined>;
flush(): Promise<boolean>;
clear(): Promise<boolean>;
tags(names: string | Array<string>): TaggedCacheContract;
protected itemKey(key: string): Promise<string>;
private calculateTTL;
private checkClosure;
private isNull;
private resolveFallback;
}