mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
21 lines
596 B
TypeScript
21 lines
596 B
TypeScript
import { AxiosStorage } from './storage';
|
|
import type { NotEmptyStorageValue, StorageValue } from './types';
|
|
|
|
export class MemoryAxiosStorage extends AxiosStorage {
|
|
constructor(readonly storage: Record<string, StorageValue> = {}) {
|
|
super();
|
|
}
|
|
|
|
readonly find = async (key: string): Promise<StorageValue> => {
|
|
return this.storage[key] || { state: 'empty' };
|
|
};
|
|
|
|
readonly set = async (key: string, value: NotEmptyStorageValue): Promise<void> => {
|
|
this.storage[key] = value;
|
|
};
|
|
|
|
readonly remove = async (key: string): Promise<void> => {
|
|
delete this.storage[key];
|
|
};
|
|
}
|