feat: add memory cache to boost performance (#2620)
* feat: add memory cache to boost performance * fix: tests * fix: logging * fix: missing commented stuff
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
import { MemoryStorageSerializer } from 'src/integrations/memory-storage/serializers/interfaces/memory-storage-serializer.interface';
|
||||
|
||||
export class MemoryStorageDefaultSerializer<T>
|
||||
implements MemoryStorageSerializer<T>
|
||||
{
|
||||
serialize(item: T): string {
|
||||
if (typeof item !== 'string') {
|
||||
throw new Error('DefaultSerializer can only serialize strings');
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
deserialize(data: string): T {
|
||||
return data as unknown as T;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
export interface MemoryStorageSerializer<T> {
|
||||
serialize(item: T): string;
|
||||
deserialize(data: string): T;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { MemoryStorageSerializer } from 'src/integrations/memory-storage/serializers/interfaces/memory-storage-serializer.interface';
|
||||
|
||||
export class MemoryStorageJsonSerializer<T>
|
||||
implements MemoryStorageSerializer<T>
|
||||
{
|
||||
serialize(item: T): string {
|
||||
return JSON.stringify(item);
|
||||
}
|
||||
|
||||
deserialize(data: string): T {
|
||||
return JSON.parse(data) as T;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user