45 lines
938 B
TypeScript
45 lines
938 B
TypeScript
import * as plugins from './levelcache.plugins.js';
|
|
|
|
export interface ICacheEntryConstructorOptions {
|
|
key?: string;
|
|
ttl: number;
|
|
typeInfo?: string;
|
|
contents: Buffer;
|
|
}
|
|
|
|
/**
|
|
* a CacheEntry
|
|
*/
|
|
export class CacheEntry
|
|
extends plugins.smartjson.Smartjson
|
|
implements ICacheEntryConstructorOptions
|
|
{
|
|
public static fromStorageJsonString(storageJsonString: string) {
|
|
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
|
|
}
|
|
|
|
@plugins.smartjson.foldDec()
|
|
accessor key: string;
|
|
|
|
@plugins.smartjson.foldDec()
|
|
accessor ttl: number;
|
|
|
|
@plugins.smartjson.foldDec()
|
|
accessor createdAt: number;
|
|
|
|
@plugins.smartjson.foldDec()
|
|
accessor typeInfo: string;
|
|
|
|
@plugins.smartjson.foldDec()
|
|
accessor contents: Buffer;
|
|
|
|
public toStorageJsonString(): string {
|
|
return this.foldToJson();
|
|
}
|
|
|
|
constructor(optionsArg: ICacheEntryConstructorOptions) {
|
|
super();
|
|
Object.assign(this, optionsArg);
|
|
}
|
|
}
|