2020-02-14 17:28:13 +00:00
|
|
|
import * as plugins from './levelcache.plugins';
|
|
|
|
|
2021-04-23 18:40:57 +00:00
|
|
|
export interface ICacheEntryConstructorOptions {
|
|
|
|
key?: string;
|
|
|
|
ttl: number;
|
|
|
|
typeInfo?: string;
|
|
|
|
contents: Buffer;
|
|
|
|
}
|
2020-02-15 22:38:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* a CacheEntry
|
|
|
|
*/
|
2021-04-23 18:41:30 +00:00
|
|
|
export class CacheEntry
|
|
|
|
extends plugins.smartjson.Smartjson
|
|
|
|
implements ICacheEntryConstructorOptions {
|
2021-04-23 18:40:57 +00:00
|
|
|
public static fromStorageJsonString(storageJsonString: string) {
|
|
|
|
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
|
|
|
|
}
|
|
|
|
|
|
|
|
@plugins.smartjson.foldDec()
|
|
|
|
public key: string;
|
|
|
|
|
|
|
|
@plugins.smartjson.foldDec()
|
|
|
|
public ttl: number;
|
|
|
|
|
|
|
|
@plugins.smartjson.foldDec()
|
|
|
|
public typeInfo: string;
|
2021-04-23 18:41:30 +00:00
|
|
|
|
2021-04-23 18:40:57 +00:00
|
|
|
@plugins.smartjson.foldDec()
|
|
|
|
contents: Buffer;
|
2020-02-15 22:38:28 +00:00
|
|
|
|
2021-04-23 18:40:57 +00:00
|
|
|
public toStorageJsonString(): string {
|
|
|
|
return this.foldToJson();
|
|
|
|
}
|
2020-02-15 22:38:28 +00:00
|
|
|
|
2021-04-23 18:40:57 +00:00
|
|
|
constructor(optionsArg: ICacheEntryConstructorOptions) {
|
|
|
|
super();
|
|
|
|
Object.assign(this, optionsArg);
|
|
|
|
}
|
2020-02-15 22:38:28 +00:00
|
|
|
}
|