1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 19:23:52 +00:00
Files
browser/libs/common/src/services/memoryStorage.service.ts
Matt Gibson 23897ae5fb Use Memory Storage directly in Session Sync (#4423)
* Use Memory Storage directly in Session Sync

* Update apps/browser/src/decorators/session-sync-observable/browser-session.decorator.spec.ts

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

* Fix up test

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
2023-01-12 14:39:33 -06:00

35 lines
834 B
TypeScript

import { AbstractMemoryStorageService } from "../abstractions/storage.service";
export class MemoryStorageService extends AbstractMemoryStorageService {
private store = new Map<string, any>();
get<T>(key: string): Promise<T> {
if (this.store.has(key)) {
const obj = this.store.get(key);
return Promise.resolve(obj as T);
}
return Promise.resolve(null);
}
async has(key: string): Promise<boolean> {
return (await this.get(key)) != null;
}
save(key: string, obj: any): Promise<any> {
if (obj == null) {
return this.remove(key);
}
this.store.set(key, obj);
return Promise.resolve();
}
remove(key: string): Promise<any> {
this.store.delete(key);
return Promise.resolve();
}
getBypassCache<T>(key: string): Promise<T> {
return this.get<T>(key);
}
}