@mittwald/kubernetes
Advanced tools
Comparing version 3.4.0 to 3.4.1
@@ -37,4 +37,6 @@ import { MetadataObject } from "../types/meta"; | ||
private api; | ||
private expirationSeconds; | ||
private cache; | ||
constructor(api: INamespacedResourceClient<R, any, any>); | ||
constructor(api: INamespacedResourceClient<R, any, any>, expirationSeconds?: number); | ||
private storeInMap; | ||
store(obj: R): Promise<void>; | ||
@@ -41,0 +43,0 @@ sync(objs: R[]): Promise<void>; |
@@ -79,9 +79,20 @@ "use strict"; | ||
class CachingLookupStore { | ||
constructor(api) { | ||
constructor(api, expirationSeconds = 3600) { | ||
this.api = api; | ||
this.expirationSeconds = expirationSeconds; | ||
this.cache = new Map(); | ||
} | ||
storeInMap(obj, map) { | ||
const { namespace, name } = obj.metadata; | ||
const key = `${namespace}/${name}`; | ||
const exp = new Date(); | ||
exp.setSeconds(exp.getSeconds() + this.expirationSeconds); | ||
map.set(key, { | ||
entry: obj, | ||
until: exp, | ||
}); | ||
} | ||
store(obj) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// no-op | ||
this.storeInMap(obj, this.cache); | ||
}); | ||
@@ -91,3 +102,7 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// no-op | ||
const newCache = new Map(); | ||
for (const obj of objs) { | ||
this.storeInMap(obj, newCache); | ||
} | ||
this.cache = newCache; | ||
}); | ||
@@ -106,8 +121,3 @@ } | ||
if (result) { | ||
const exp = new Date(); | ||
exp.setSeconds(exp.getSeconds() + 3600); | ||
this.cache.set(key, { | ||
entry: result, | ||
until: exp, | ||
}); | ||
this.store(result); | ||
} | ||
@@ -119,3 +129,5 @@ return result; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// no-op | ||
const { namespace, name } = obj.metadata; | ||
const key = `${namespace}/${name}`; | ||
this.cache.delete(key); | ||
}); | ||
@@ -122,0 +134,0 @@ } |
@@ -64,3 +64,3 @@ { | ||
}, | ||
"version": "3.4.0" | ||
"version": "3.4.1" | ||
} |
Sorry, the diff of this file is not supported yet
193791
3531