Skip to content

Commit f18d460

Browse files
committed
fix: ensure we use seconds everywhere
1 parent cc0e4d1 commit f18d460

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

storages/lru-redis/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
LRU local cache and central redis cache,
44
if not found local, redis is checked and in case there is a result it is saved locally
5+
6+
all timeout values are in SECONDS

storages/lru-redis/src/LRUWithRedisStorage.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Redis from "ioredis";
55

66
export class LRUWithRedisStorage implements AsynchronousCacheType {
77
private myCache: LRU<string, any>;
8+
/** maxAge and ttl in seconds! */
89
private options: LRU.Options<string, any>;
910

1011
constructor(
@@ -16,7 +17,10 @@ export class LRUWithRedisStorage implements AsynchronousCacheType {
1617
maxAge: 86400,
1718
...options
1819
}
19-
this.myCache = new LRU(this.options);
20+
this.myCache = new LRU({
21+
...this.options,
22+
maxAge: (this.options.maxAge || 86400) * 1000 // in ms
23+
});
2024
}
2125

2226
public async getItem<T>(key: string): Promise<T | undefined> {
@@ -42,6 +46,7 @@ export class LRUWithRedisStorage implements AsynchronousCacheType {
4246
return localCache ?? undefined;
4347
}
4448

49+
/** ttl in seconds! */
4550
public async setItem(key: string, content: any, options?: { ttl?: number }): Promise<void> {
4651
this.myCache.set(key, content);
4752
if (this.options?.maxAge) {
@@ -53,6 +58,9 @@ export class LRUWithRedisStorage implements AsynchronousCacheType {
5358

5459
public async clear(): Promise<void> {
5560
// flush not supported, recreate local lru cache instance
56-
this.myCache = new LRU(this.options);
61+
this.myCache = new LRU({
62+
...this.options,
63+
maxAge: (this.options.maxAge || 86400) * 1000 // in ms
64+
});
5765
}
5866
}

storages/lru/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ import LRUStorage from 'node-ts-cache-lru-storage';
1010
1111
const myStrategy = new ExpirationStrategy(new LRUStorage());
1212
```
13+
14+
all timeout values are in SECONDS

storages/lru/src/LRUStorage.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ export class LRUStorage
99
implements SynchronousCacheType, MultiSynchronousCacheType {
1010
myCache: LRU<string, any>;
1111

12-
constructor(private options: LRU.Options<string, any>) {
13-
this.myCache = new LRU(options);
12+
constructor(
13+
/** maxAge in seconds! */ private options: LRU.Options<string, any>
14+
) {
15+
this.myCache = new LRU({
16+
...options,
17+
maxAge: options.maxAge ? options.maxAge * 1000 : undefined,
18+
});
1419
}
1520

1621
getItems<T>(keys: string[]): { [key: string]: T | undefined } {
@@ -33,6 +38,9 @@ export class LRUStorage
3338

3439
public clear(): void {
3540
// flush not supported, recreate lru cache instance
36-
this.myCache = new LRU(this.options);
41+
this.myCache = new LRU({
42+
...this.options,
43+
maxAge: this.options.maxAge ? this.options.maxAge * 1000 : undefined, // in ms
44+
});
3745
}
3846
}

storages/redisio/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ import RedisIOStorage from 'node-ts-cache-redisio-storage';
77
88
const myStrategy = new ExpirationStrategy(new RedisIOStorage());
99
```
10+
11+
all timeout values are in SECONDS

0 commit comments

Comments
 (0)