@brandtg/flapjack 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache.d.ts +6 -6
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +4 -4
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { FeatureFlagModel } from "./model.js";
|
|
2
2
|
export interface Cache<T> {
|
|
3
|
-
get(key: string): T | undefined
|
|
4
|
-
set(key: string, value: T, ttl?: number): void
|
|
5
|
-
delete(key: string): void
|
|
3
|
+
get(key: string): Promise<T | undefined>;
|
|
4
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
5
|
+
delete(key: string): Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Simple in-memory cache with TTL support.
|
|
9
9
|
*/
|
|
10
10
|
export declare class InMemoryCache<T> implements Cache<T> {
|
|
11
11
|
private cache;
|
|
12
|
-
get(key: string): T | undefined
|
|
13
|
-
set(key: string, value: T, ttl?: number): void
|
|
14
|
-
delete(key: string): void
|
|
12
|
+
get(key: string): Promise<T | undefined>;
|
|
13
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
14
|
+
delete(key: string): Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Clear all expired entries from the cache.
|
|
17
17
|
*/
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG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,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,GAAG,OAAO,CAAC,OAAO,CAAC;CAuBrB"}
|
package/dist/cache.js
CHANGED
|
@@ -5,7 +5,7 @@ const DEFAULT_TTL = 60 * 5; // 5 minutes
|
|
|
5
5
|
*/
|
|
6
6
|
export class InMemoryCache {
|
|
7
7
|
cache = new Map();
|
|
8
|
-
get(key) {
|
|
8
|
+
async get(key) {
|
|
9
9
|
const entry = this.cache.get(key);
|
|
10
10
|
if (!entry) {
|
|
11
11
|
return undefined;
|
|
@@ -18,11 +18,11 @@ export class InMemoryCache {
|
|
|
18
18
|
}
|
|
19
19
|
return entry.value;
|
|
20
20
|
}
|
|
21
|
-
set(key, value, ttl) {
|
|
21
|
+
async set(key, value, ttl) {
|
|
22
22
|
const expiresAt = ttl !== undefined ? Date.now() + ttl * 1000 : undefined;
|
|
23
23
|
this.cache.set(key, { value, expiresAt });
|
|
24
24
|
}
|
|
25
|
-
delete(key) {
|
|
25
|
+
async delete(key) {
|
|
26
26
|
this.cache.delete(key);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -78,7 +78,7 @@ export class FeatureFlagCache {
|
|
|
78
78
|
// Generate cache key
|
|
79
79
|
const cacheKey = this.generateCacheKey({ name, user, roles, groups });
|
|
80
80
|
// Try to get from cache first
|
|
81
|
-
const cachedResult = this.cache.get(cacheKey);
|
|
81
|
+
const cachedResult = await this.cache.get(cacheKey);
|
|
82
82
|
if (cachedResult !== undefined) {
|
|
83
83
|
return cachedResult;
|
|
84
84
|
}
|