/** * 2011 Peter 'Pita' Martischka * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS-IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { Logger } from "./logging"; type CacheEntry = { value: unknown; dirty: SelfContainedPromise | null; writingInProgress: boolean; }; export type CacheSettings = { bulkLimit: number; cache: number; writeInterval: number; json: boolean; charset: string; }; type LegacyWrappedDB = { isAsync?: boolean; settings?: Partial; logger?: Logger; [key: string]: unknown; }; export type Metrics = { lockAwaits: number; lockAcquires: number; lockReleases: number; reads: number; readsFailed: number; readsFinished: number; readsFromCache: number; readsFromDb: number; readsFromDbFailed: number; readsFromDbFinished: number; writes: number; writesFailed: number; writesFinished: number; writesObsoleted: number; writesToDb: number; writesToDbFailed: number; writesToDbFinished: number; writesToDbRetried: number; }; export declare class LRU { private _capacity; private _evictable; private _cache; /** * @param evictable Optional predicate that dictates whether it is permissable to evict the entry * if it is old and the cache is over capacity. Warning: Non-evictable entries can cause the * cache to go over capacity. */ constructor(capacity: number, evictable?: (k: string, v: CacheEntry) => boolean); [Symbol.iterator](): IterableIterator<[string, CacheEntry]>; get(k: string, isUse?: boolean): CacheEntry | undefined; set(k: string, v: CacheEntry): void; evictOld(): void; } declare class SelfContainedPromise extends Promise { done: (err?: Error | null) => void; constructor(executor?: ((resolve: () => void, reject: (reason?: unknown) => void) => void) | null); } export declare class Database { private wrappedDB; logger: Logger; readonly settings: Readonly; private readonly buffer; private _flushPaused; private _flushPausedCount; private readonly _locks; private readonly _dirtyKeys; private _flushDone; metrics: Metrics; private _flushTimer; private _keepAlive; constructor(wrappedDB: LegacyWrappedDB, settings: Partial | null | undefined, logger: Logger); private _lock; private _unlock; private _scheduleFlush; private _cancelFlushTimer; private _pauseFlush; private _resumeFlush; init(): Promise; close(): Promise; get(key: string): Promise; private _getLocked; findKeys(key: string, notKey?: string): Promise; findKeysPaged(key: string, notKey: string | null | undefined, options: { limit: number; after?: string; }): Promise; remove(key: string): Promise; set(key: string, value: unknown): Promise; private _setLocked; setSub(key: string, sub: string[], value: unknown): Promise; getSub(key: string, sub: string[]): Promise; flush(): Promise; private _write; } export declare const exportedForTesting: { LRU: typeof LRU; }; export {}; //# sourceMappingURL=CacheAndBufferLayer.d.ts.map