Import other modules into monorepo
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
32
src/support/cache/Cache.ts
vendored
32
src/support/cache/Cache.ts
vendored
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Abstract interface class for an application cache object.
|
||||
*/
|
||||
export abstract class Cache {
|
||||
/**
|
||||
* Fetch a value from the cache by its key.
|
||||
* @param {string} key
|
||||
* @return Promise<any|undefined>
|
||||
*/
|
||||
public abstract fetch(key: string): string | undefined | Promise<string | undefined>;
|
||||
|
||||
/**
|
||||
* Store the given value in the cache by key.
|
||||
* @param {string} key
|
||||
* @param {string} value
|
||||
* @param {Date} [expires]
|
||||
*/
|
||||
public abstract put(key: string, value: string, expires?: Date): void | Promise<void>;
|
||||
|
||||
/**
|
||||
* Check if the cache has the given key.
|
||||
* @param {string} key
|
||||
* @return Promise<boolean>
|
||||
*/
|
||||
public abstract has(key: string): boolean | Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Drop the given key from the cache.
|
||||
* @param {string} key
|
||||
*/
|
||||
public abstract drop(key: string): void | Promise<void>;
|
||||
}
|
||||
6
src/support/cache/CacheFactory.ts
vendored
6
src/support/cache/CacheFactory.ts
vendored
@@ -6,11 +6,11 @@ import {
|
||||
isInstantiable,
|
||||
DEPENDENCY_KEYS_METADATA_KEY,
|
||||
DEPENDENCY_KEYS_PROPERTY_METADATA_KEY
|
||||
} from "@extollo/di"
|
||||
import {Collection, ErrorWithContext} from "@extollo/util"
|
||||
} from "../../di"
|
||||
import {Collection, ErrorWithContext} from "../../util"
|
||||
import {Logging} from "../../service/Logging";
|
||||
import {Config} from "../../service/Config";
|
||||
import {Cache} from "./Cache"
|
||||
import {Cache} from "../../util";
|
||||
import {MemoryCache} from "./MemoryCache";
|
||||
|
||||
/**
|
||||
|
||||
11
src/support/cache/MemoryCache.ts
vendored
11
src/support/cache/MemoryCache.ts
vendored
@@ -1,5 +1,4 @@
|
||||
import {Collection} from "@extollo/util"
|
||||
import {Cache} from "./Cache"
|
||||
import {Cache, Collection, Awaitable} from "../../util"
|
||||
|
||||
/**
|
||||
* An in-memory implementation of the Cache.
|
||||
@@ -9,7 +8,7 @@ export class MemoryCache extends Cache {
|
||||
/** Static collection of in-memory cache items. */
|
||||
private static cacheItems: Collection<{key: string, value: string, expires?: Date}> = new Collection<{key: string; value: string, expires?: Date}>()
|
||||
|
||||
public fetch(key: string): string | Promise<string | undefined> | undefined {
|
||||
public fetch(key: string): Awaitable<string|undefined> {
|
||||
const now = new Date()
|
||||
return MemoryCache.cacheItems
|
||||
.where('key', '=', key)
|
||||
@@ -18,7 +17,7 @@ export class MemoryCache extends Cache {
|
||||
})?.value
|
||||
}
|
||||
|
||||
public put(key: string, value: string, expires?: Date): void | Promise<void> {
|
||||
public put(key: string, value: string, expires?: Date): Awaitable<void> {
|
||||
const existing = MemoryCache.cacheItems.firstWhere('key', '=', key)
|
||||
if ( existing ) {
|
||||
existing.value = value
|
||||
@@ -28,7 +27,7 @@ export class MemoryCache extends Cache {
|
||||
}
|
||||
}
|
||||
|
||||
public has(key: string): boolean | Promise<boolean> {
|
||||
public has(key: string): Awaitable<boolean> {
|
||||
const now = new Date()
|
||||
return !!MemoryCache.cacheItems
|
||||
.where('key', '=', key)
|
||||
@@ -37,7 +36,7 @@ export class MemoryCache extends Cache {
|
||||
})
|
||||
}
|
||||
|
||||
public drop(key: string): void | Promise<void> {
|
||||
public drop(key: string): Awaitable<void> {
|
||||
MemoryCache.cacheItems = MemoryCache.cacheItems.where('key', '!=', key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user