Path: blob/main/components/gitpod-db/src/data-cache.ts
2498 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { injectable } from "inversify";78/**9* A cache that can be used to cache expensive operations, such as retrieving data from the database.10*/11export interface DataCache {12/**13* Retrieves the value for the given key from the cache. If the value is not in the cache, the provider is called and the result is stored in the cache.14* @param key the key to retrieve the value for. Should be segmented using `:`. For example: `user:123`15* @param provider the provider to call if the value is not in the cache16*/17get<T>(key: string, provider: () => Promise<T | undefined>): Promise<T | undefined>;1819/**20* @param keyPattern the key pattern to invalidate. The `*` denotes a wildcard segment. For example: `user:*` invalidates all keys starting with `user:`21*/22invalidate(keyPattern: string): Promise<void>;23}24export const DataCache = Symbol("DataCache");2526@injectable()27export class DataCacheNoop implements DataCache {28get<T>(key: string, provider: () => Promise<T | undefined>): Promise<T | undefined> {29return provider();30}3132async invalidate(partialKey: string): Promise<void> {33// noop34}35}363738