1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00
Files
browser/libs/common/src/services/memoryStorage.service.ts
Matt Gibson 750ff736cd [ps-2003] Ps/ps 1854 fix pin (#4193)
* Await in `has` calls.

* Add disk cache to browser synced items

Note: `Map` doesn't serialize nicely so it's easier to swap over to a
`Record` object for out cache

* Mock and await init promises in tests

* Remove redundant settings checks
2022-12-06 16:26:42 -06:00

37 lines
822 B
TypeScript

import {
AbstractStorageService,
MemoryStorageServiceInterface,
} from "../abstractions/storage.service";
export class MemoryStorageService
extends AbstractStorageService
implements MemoryStorageServiceInterface
{
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();
}
}