@melchyore/adonis-cache
Version:
Cache package for AdonisJS V5
68 lines (67 loc) • 3.93 kB
TypeScript
/// <reference types="@adonisjs/application/build/adonis-typings/application" />
import type { ApplicationContract } from '@ioc:Adonis/Core/Application';
import type { CacheStoreContract, CacheConfig, RepositoryContract, AsyncFunction, CacheStoresList, InMemoryStoreConfig, RedisStoreConfig, MemcachedStoreConfig, DynamoDBStoreConfig, DatabaseStoreConfig, FileStoreConfig, PutManyResult, TaggedCacheContract } from '@ioc:Adonis/Addons/Cache';
import { Manager } from '@poppinss/manager';
import Repository from './Repository';
import Memcached from './Stores/Memcached';
import InMemory from './Stores/InMemory';
import Redis from './Stores/Redis';
import DynamoDB from './Stores/DynamoDB';
import Database from './Stores/Database';
import File from './Stores/File';
export default class CacheManager extends Manager<ApplicationContract, CacheStoreContract, RepositoryContract<keyof CacheStoresList>, {
[P in keyof CacheStoresList]: RepositoryContract<P>;
}> {
private app;
private config;
/**
* Cache all stores instances.
*/
protected singleton: boolean;
/**
* Find if cache is ready to be used
*/
private isReady;
private emitter;
constructor(app: ApplicationContract, config: CacheConfig);
createInMemory(_: string, __: InMemoryStoreConfig): InMemory;
createMemcached(_: string, __: MemcachedStoreConfig): Memcached;
createRedis(_: string, config: RedisStoreConfig): Redis;
createDynamodb(_: string, config: DynamoDBStoreConfig): DynamoDB;
createDatabase(_: string, config: DatabaseStoreConfig): Database;
createFile(_: string, config: FileStoreConfig): File;
use(store?: keyof CacheStoresList): RepositoryContract<keyof CacheStoresList>;
get<T = any>(key: string, fallback?: T | AsyncFunction<T>): Promise<T | null>;
many<T extends Record<string, any>>(keys: Array<string>): Promise<T>;
add<T = any>(key: string, value: T, ttl?: number): Promise<boolean>;
put<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>;
has(key: string): Promise<boolean>;
missing(key: string): Promise<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>;
pull<T = any>(key: string): Promise<T | null>;
remember<T = any>(key: string, ttl: number | undefined | 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>;
forget(key: string): Promise<boolean>;
forgetMultiple(keys: Array<string>): Promise<Record<string, boolean>>;
flush(): Promise<boolean>;
clear(): Promise<boolean>;
tags(names: string | Array<string>): TaggedCacheContract;
protected getDefaultMappingName(): keyof CacheStoresList;
protected getMappingConfig(mappingName: keyof CacheStoresList): InMemoryStoreConfig | RedisStoreConfig | MemcachedStoreConfig | DynamoDBStoreConfig | DatabaseStoreConfig | FileStoreConfig | {
driver: "dummy";
};
protected getMappingDriver(mappingName: keyof CacheStoresList): string | undefined;
/**
* Since we don't expose the drivers instances directly, we wrap them
* inside the repository instance.
*/
protected wrapDriverResponse<Name extends keyof CacheStoresList>(mappingName: Name, driver: CacheStoreContract): Repository<keyof CacheStoresList>;
private getPrefix;
private validateConfig;
}