levelcache/ts/levelcache.classes.cacheentry.ts

45 lines
921 B
TypeScript
Raw Permalink Normal View History

2022-03-22 21:45:12 +00:00
import * as plugins from './levelcache.plugins.js';
2020-02-14 17:28:13 +00:00
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
2022-03-22 21:45:12 +00:00
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()
2022-03-22 21:45:12 +00:00
public createdAt: number;
2021-04-23 18:41:30 +00:00
2021-04-23 18:40:57 +00:00
@plugins.smartjson.foldDec()
2022-03-22 21:45:12 +00:00
public typeInfo: string;
2020-02-15 22:38:28 +00:00
@plugins.smartjson.foldDec()
2022-03-22 21:45:12 +00:00
contents: Buffer;
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
}