@melchyore/adonis-cache
Version:
Cache package for AdonisJS V5
34 lines (33 loc) • 1.55 kB
TypeScript
/// <reference types="@adonisjs/lucid" />
import type { QueryClientContract } from '@ioc:Adonis/Lucid/Database';
import type { CacheStoreContract } from '@ioc:Adonis/Addons/Cache';
import BaseStore from './BaseStore';
export default class Database extends BaseStore implements CacheStoreContract {
private connection;
private table;
constructor(connection: QueryClientContract, table: string);
get<T = any>(key: string): Promise<T | null>;
many<T extends Record<string, any>>(keys: Array<string>): Promise<T>;
has(key: string): Promise<boolean>;
put<T = any>(key: string, value: T, ttl: number): Promise<boolean>;
/**
* Store a new item in the cache if the key doesn't exist.
* Otherwise, update a stale item with a value and a new TTL.
*/
add<T = any>(_key: string, value: T, ttl: number): Promise<boolean>;
putMany(list: Record<string, unknown>, ttl: number): Promise<Array<boolean>>;
increment(key: string, value: number): Promise<number | boolean>;
decrement(key: string, value: number): Promise<number | boolean>;
putManyForever(list: Record<string, unknown>): Promise<Array<boolean>>;
forever<T = any>(key: string, value: T): Promise<boolean>;
forget(key: string): Promise<boolean>;
flush(): Promise<boolean>;
private insert;
private incrementValue;
private decrementValue;
/**
* Check if query result is an Array or a number.
* If it's an array, return its length.
*/
private getResultNumber;
}