fix(core): update
This commit is contained in:
@ -1,3 +1,2 @@
|
||||
export * from './levelcache.classes.levelcache';
|
||||
export * from './levelcache.classes.cacheentry';
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { CacheEntry } from "./levelcache.classes.cacheentry";
|
||||
import { CacheEntry } from './levelcache.classes.cacheentry';
|
||||
|
||||
export abstract class AbstractCache {
|
||||
public abstract ready: Promise<void>;
|
||||
public abstract status: 'active' | 'inactive';
|
||||
|
||||
|
||||
// Blobs
|
||||
/**
|
||||
* store a Blob
|
||||
@ -22,4 +22,4 @@ export abstract class AbstractCache {
|
||||
* cleans the cache
|
||||
*/
|
||||
public abstract clean(): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import { CacheEntry } from './levelcache.classes.cacheentry';
|
||||
export class CacheDiskManager extends AbstractCache {
|
||||
private levelCacheRef: LevelCache;
|
||||
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||
|
||||
|
||||
public ready = this.readyDeferred.promise;
|
||||
public status: 'active' | 'inactive';
|
||||
public status: 'active' | 'inactive';
|
||||
public fsPath: string;
|
||||
public maxCacheSizeInMb: number;
|
||||
|
||||
@ -24,7 +24,10 @@ export class CacheDiskManager extends AbstractCache {
|
||||
|
||||
public async init() {
|
||||
if (this.levelCacheRef.options.diskStoragePath) {
|
||||
this.fsPath = plugins.path.join(this.levelCacheRef.options.diskStoragePath, this.levelCacheRef.options.cacheId);
|
||||
this.fsPath = plugins.path.join(
|
||||
this.levelCacheRef.options.diskStoragePath,
|
||||
this.levelCacheRef.options.cacheId
|
||||
);
|
||||
} else {
|
||||
this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId);
|
||||
}
|
||||
@ -35,12 +38,17 @@ export class CacheDiskManager extends AbstractCache {
|
||||
}
|
||||
|
||||
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||
const fileString = await plugins.smartfile.fs.toStringSync(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
||||
const fileString = await plugins.smartfile.fs.toStringSync(
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||
);
|
||||
return CacheEntry.fromStorageJsonString(fileString);
|
||||
}
|
||||
|
||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||
await plugins.smartfile.memory.toFs(cacheEntryArg.foldToJson(), plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
||||
await plugins.smartfile.memory.toFs(
|
||||
cacheEntryArg.foldToJson(),
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||
);
|
||||
}
|
||||
|
||||
public async checkKeyPresence(keyArg): Promise<boolean> {
|
||||
|
@ -7,7 +7,7 @@ export class CacheMemoryManager extends AbstractCache {
|
||||
private levelCacheRef: LevelCache;
|
||||
private fastMap = new plugins.lik.FastMap<CacheEntry>();
|
||||
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||
|
||||
|
||||
public ready = this.readyDeferred.promise;
|
||||
public status: 'active' | 'inactive';
|
||||
|
||||
@ -41,5 +41,4 @@ export class CacheMemoryManager extends AbstractCache {
|
||||
public async clean() {
|
||||
this.fastMap.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,10 @@ export class CacheS3Manager extends AbstractCache {
|
||||
}
|
||||
|
||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||
await this.s3CacheDir.fastStore(encodeURIComponent(keyArg), cacheEntryArg.toStorageJsonString());
|
||||
await this.s3CacheDir.fastStore(
|
||||
encodeURIComponent(keyArg),
|
||||
cacheEntryArg.toStorageJsonString()
|
||||
);
|
||||
}
|
||||
|
||||
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||
|
@ -10,7 +10,9 @@ export interface ICacheEntryConstructorOptions {
|
||||
/**
|
||||
* a CacheEntry
|
||||
*/
|
||||
export class CacheEntry extends plugins.smartjson.Smartjson implements ICacheEntryConstructorOptions {
|
||||
export class CacheEntry
|
||||
extends plugins.smartjson.Smartjson
|
||||
implements ICacheEntryConstructorOptions {
|
||||
public static fromStorageJsonString(storageJsonString: string) {
|
||||
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
|
||||
}
|
||||
@ -23,7 +25,7 @@ export class CacheEntry extends plugins.smartjson.Smartjson implements ICacheEnt
|
||||
|
||||
@plugins.smartjson.foldDec()
|
||||
public typeInfo: string;
|
||||
|
||||
|
||||
@plugins.smartjson.foldDec()
|
||||
contents: Buffer;
|
||||
|
||||
|
@ -46,7 +46,7 @@ export class CacheRouter {
|
||||
if (!returnCache && this.levelCacheRef.options.persistentCache) {
|
||||
const checkCache = (cacheArg: AbstractCache) => {
|
||||
const resultPromise = cacheArg.checkKeyPresence(keyArg);
|
||||
resultPromise.then(hasKeyArg => {
|
||||
resultPromise.then((hasKeyArg) => {
|
||||
if (hasKeyArg) {
|
||||
done.resolve(cacheArg);
|
||||
}
|
||||
@ -56,7 +56,7 @@ export class CacheRouter {
|
||||
Promise.all([
|
||||
checkCache(this.levelCacheRef.cacheMemoryManager),
|
||||
checkCache(this.levelCacheRef.cacheDiskManager),
|
||||
checkCache(this.levelCacheRef.cacheMemoryManager)
|
||||
checkCache(this.levelCacheRef.cacheMemoryManager),
|
||||
]).then(() => {
|
||||
done.resolve(returnCache);
|
||||
});
|
||||
|
@ -79,12 +79,11 @@ export class LevelCache extends AbstractCache {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||
return plugins.smartpromise.getFirstTrueOrFalse([
|
||||
this.cacheMemoryManager.checkKeyPresence(keyArg),
|
||||
this.cacheDiskManager.checkKeyPresence(keyArg),
|
||||
this.cacheS3Manager.checkKeyPresence(keyArg)
|
||||
this.cacheS3Manager.checkKeyPresence(keyArg),
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user