/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular/build/src/tools/esbuild/lmdb-cache-store.ts
59 строк
1 KB
Charles Lyding
feat(@angular/build): add built-in SQLite cache store fallback
02 июл 2026, 09:44
02 июл 2026, 09:44
34d558c
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { RootDatabase, open } from 'lmdb'; import { Cache, PersistentCacheStore } from './cache'; export class LmdbCacheStore implements PersistentCacheStore<unknown> { readonly #cacheFileUrl; #db: RootDatabase | undefined; constructor(readonly cachePath: string) { this.#cacheFileUrl = cachePath; } #ensureCacheFile(): RootDatabase { this.#db ??= open({ path: this.#cacheFileUrl, compression: true, }); return this.#db; } // eslint-disable-next-line @typescript-eslint/no-explicit-any async get(key: string): Promise<any> { const db = this.#ensureCacheFile(); const value = db.get(key); return value; } has(key: string): boolean { return this.#ensureCacheFile().doesExist(key); } async set(key: string, value: unknown): Promise<this> { const db = this.#ensureCacheFile(); await db.put(key, value); return this; } createCache<V = unknown>(namespace: string): Cache<V> { return new Cache(this, namespace); } async close() { try { await this.#db?.close(); } catch { // Failure to close should not be fatal } } }