fix(core): Update CI workflows and dependencies; apply small bugfixes and formatting improvements
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/levelcache',
|
||||
version: '3.1.1',
|
||||
version: '3.1.2',
|
||||
description: 'A versatile caching solution offering multi-level storage utilizing memory, disk, and Amazon S3 for efficient data management and backup.'
|
||||
}
|
||||
|
@@ -8,7 +8,10 @@ export abstract class AbstractCache {
|
||||
/**
|
||||
* store a Blob
|
||||
*/
|
||||
public abstract storeCacheEntryByKey(keyArg: string, valueArg: CacheEntry): Promise<void>;
|
||||
public abstract storeCacheEntryByKey(
|
||||
keyArg: string,
|
||||
valueArg: CacheEntry,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* retrieve cache entry
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as plugins from './levelcache.plugins.js';
|
||||
import * as paths from './levelcache.paths.js';
|
||||
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||
import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
|
||||
import {
|
||||
type ILevelCacheConstructorOptions,
|
||||
LevelCache,
|
||||
} from './levelcache.classes.levelcache.js';
|
||||
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||
|
||||
/**
|
||||
@@ -26,10 +29,13 @@ export class CacheDiskManager extends AbstractCache {
|
||||
if (this.levelCacheRef.options.diskStoragePath) {
|
||||
this.fsPath = plugins.path.join(
|
||||
this.levelCacheRef.options.diskStoragePath,
|
||||
this.levelCacheRef.options.cacheId
|
||||
this.levelCacheRef.options.cacheId,
|
||||
);
|
||||
} else {
|
||||
this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId);
|
||||
this.fsPath = plugins.path.join(
|
||||
paths.nogitDir,
|
||||
this.levelCacheRef.options.cacheId,
|
||||
);
|
||||
}
|
||||
if (this.status === 'active') {
|
||||
plugins.smartfile.fs.ensureDirSync(this.fsPath);
|
||||
@@ -39,7 +45,7 @@ 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))
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||
);
|
||||
return CacheEntry.fromStorageJsonString(fileString);
|
||||
}
|
||||
@@ -47,16 +53,20 @@ export class CacheDiskManager extends AbstractCache {
|
||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||
await plugins.smartfile.memory.toFs(
|
||||
cacheEntryArg.foldToJson(),
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||
);
|
||||
}
|
||||
|
||||
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||
return plugins.smartfile.fs.isFile(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
||||
return plugins.smartfile.fs.isFile(
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||
);
|
||||
}
|
||||
|
||||
public async deleteCacheEntryByKey(keyArg: string) {
|
||||
await plugins.smartfile.fs.remove(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
||||
await plugins.smartfile.fs.remove(
|
||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||
);
|
||||
}
|
||||
|
||||
public async cleanOutdated() {}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as plugins from './levelcache.plugins.js';
|
||||
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||
import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
|
||||
import {
|
||||
type ILevelCacheConstructorOptions,
|
||||
LevelCache,
|
||||
} from './levelcache.classes.levelcache.js';
|
||||
|
||||
export class CacheMemoryManager extends AbstractCache {
|
||||
private levelCacheRef: LevelCache;
|
||||
@@ -22,7 +25,10 @@ export class CacheMemoryManager extends AbstractCache {
|
||||
this.readyDeferred.resolve();
|
||||
}
|
||||
|
||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry): Promise<void> {
|
||||
public async storeCacheEntryByKey(
|
||||
keyArg: string,
|
||||
cacheEntryArg: CacheEntry,
|
||||
): Promise<void> {
|
||||
this.fastMap.addToMap(keyArg, cacheEntryArg, { force: true });
|
||||
}
|
||||
|
||||
|
@@ -24,15 +24,21 @@ export class CacheS3Manager extends AbstractCache {
|
||||
|
||||
public async init() {
|
||||
if (this.levelCacheRef.options.s3Config) {
|
||||
this.smartbucket = new plugins.smartbucket.SmartBucket(this.levelCacheRef.options.s3Config);
|
||||
this.smartbucket = new plugins.smartbucket.SmartBucket(
|
||||
this.levelCacheRef.options.s3Config,
|
||||
);
|
||||
this.s3CacheBucket = await this.smartbucket.getBucketByName('');
|
||||
this.s3CacheDir = await (
|
||||
await this.s3CacheBucket.getBaseDirectory()
|
||||
).getSubDirectoryByName(this.levelCacheRef.options.cacheId);
|
||||
if (this.levelCacheRef.options.maxS3StorageInMB) {
|
||||
console.log(`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`);
|
||||
console.log(
|
||||
`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`,
|
||||
);
|
||||
} else {
|
||||
console.log(`s3 cache started without limit. Automatically applying timebox of 1 month`);
|
||||
console.log(
|
||||
`s3 cache started without limit. Automatically applying timebox of 1 month`,
|
||||
);
|
||||
}
|
||||
this.status = 'active';
|
||||
} else {
|
||||
@@ -42,9 +48,11 @@ export class CacheS3Manager extends AbstractCache {
|
||||
}
|
||||
|
||||
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||
const jsonFileString = (await this.s3CacheDir.fastGet({
|
||||
path: encodeURIComponent(keyArg),
|
||||
})).toString();
|
||||
const jsonFileString = (
|
||||
await this.s3CacheDir.fastGet({
|
||||
path: encodeURIComponent(keyArg),
|
||||
})
|
||||
).toString();
|
||||
const cacheEntry = CacheEntry.fromStorageJsonString(jsonFileString);
|
||||
return cacheEntry;
|
||||
}
|
||||
@@ -52,7 +60,7 @@ export class CacheS3Manager extends AbstractCache {
|
||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||
await this.s3CacheDir.fastPut({
|
||||
path: encodeURIComponent(keyArg),
|
||||
contents: cacheEntryArg.toStorageJsonString()
|
||||
contents: cacheEntryArg.toStorageJsonString(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -14,12 +14,18 @@ export class CacheRouter {
|
||||
/**
|
||||
* gets the relevant cache to perform a store action on
|
||||
*/
|
||||
async getCacheForStoreAction(keyArg: string, cacheEntry: CacheEntry): Promise<AbstractCache> {
|
||||
async getCacheForStoreAction(
|
||||
keyArg: string,
|
||||
cacheEntry: CacheEntry,
|
||||
): Promise<AbstractCache> {
|
||||
let returnCache: AbstractCache;
|
||||
const mbToBytesMultiplier = 1000 * 1000;
|
||||
const maxMemoryBytes = this.levelCacheRef.options.maxMemoryStorageInMB * mbToBytesMultiplier;
|
||||
const maxDiskBytes = this.levelCacheRef.options.maxDiskStorageInMB * mbToBytesMultiplier;
|
||||
const maxS3Bytes = this.levelCacheRef.options.maxS3StorageInMB * mbToBytesMultiplier;
|
||||
const maxMemoryBytes =
|
||||
this.levelCacheRef.options.maxMemoryStorageInMB * mbToBytesMultiplier;
|
||||
const maxDiskBytes =
|
||||
this.levelCacheRef.options.maxDiskStorageInMB * mbToBytesMultiplier;
|
||||
const maxS3Bytes =
|
||||
this.levelCacheRef.options.maxS3StorageInMB * mbToBytesMultiplier;
|
||||
|
||||
switch (true) {
|
||||
case cacheEntry.contents.byteLength <= maxMemoryBytes &&
|
||||
|
@@ -64,9 +64,15 @@ export class LevelCache extends AbstractCache {
|
||||
}
|
||||
|
||||
// store things
|
||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry): Promise<void> {
|
||||
public async storeCacheEntryByKey(
|
||||
keyArg: string,
|
||||
cacheEntryArg: CacheEntry,
|
||||
): Promise<void> {
|
||||
cacheEntryArg.key = keyArg;
|
||||
const targetCache = await this.cacheRouter.getCacheForStoreAction(keyArg, cacheEntryArg);
|
||||
const targetCache = await this.cacheRouter.getCacheForStoreAction(
|
||||
keyArg,
|
||||
cacheEntryArg,
|
||||
);
|
||||
cacheEntryArg.createdAt = Date.now();
|
||||
await targetCache.storeCacheEntryByKey(keyArg, cacheEntryArg);
|
||||
}
|
||||
@@ -76,7 +82,8 @@ export class LevelCache extends AbstractCache {
|
||||
* retrieve cache entry
|
||||
*/
|
||||
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||
const targetCache = await this.cacheRouter.getCacheForRetrieveAction(keyArg);
|
||||
const targetCache =
|
||||
await this.cacheRouter.getCacheForRetrieveAction(keyArg);
|
||||
if (targetCache) {
|
||||
const cacheEntry = await targetCache.retrieveCacheEntryByKey(keyArg);
|
||||
if (cacheEntry.createdAt + cacheEntry.ttl < Date.now()) {
|
||||
|
@@ -2,6 +2,6 @@ import * as plugins from './levelcache.plugins.js';
|
||||
|
||||
export const packageDir = plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../'
|
||||
'../',
|
||||
);
|
||||
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
||||
|
@@ -31,6 +31,4 @@ export {
|
||||
// @tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export {
|
||||
tsclass,
|
||||
};
|
||||
export { tsclass };
|
||||
|
Reference in New Issue
Block a user