Files
levelcache/ts/levelcache.classes.cacheentry.ts

45 lines
938 B
TypeScript
Raw Normal View History

2022-03-22 22:45:12 +01: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 22:45:12 +01: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()
accessor key: string;
2021-04-23 18:40:57 +00:00
@plugins.smartjson.foldDec()
accessor ttl: number;
2021-04-23 18:40:57 +00:00
@plugins.smartjson.foldDec()
accessor createdAt: number;
2021-04-23 18:41:30 +00:00
2021-04-23 18:40:57 +00:00
@plugins.smartjson.foldDec()
accessor typeInfo: string;
2020-02-15 22:38:28 +00:00
@plugins.smartjson.foldDec()
accessor 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
}