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:
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