@darco2903/expiry-cache 2.0.0-beta.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/README.md +70 -0
- package/dist/ExpiryCache.d.ts +27 -0
- package/dist/ExpiryCache.js +41 -0
- package/dist/ExpiryCacheAsync.d.ts +29 -0
- package/dist/ExpiryCacheAsync.js +52 -0
- package/dist/ExpiryCacheBase.d.ts +95 -0
- package/dist/ExpiryCacheBase.js +115 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Expiry Cache
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
A simple in-memory cache with expiry functionality. It allows you to store data that automatically expires after a specified duration, with support for synchronous and asynchronous data fetching.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You can find the package here: [**@darco2903/expiry-cache**](https://github.com/users/Darco2903/packages/npm/package/expiry-cache)
|
|
10
|
+
|
|
11
|
+
## Example Usage
|
|
12
|
+
|
|
13
|
+
### Basic Example
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { ExpiryCache } from "@darco2903/expiry-cache";
|
|
17
|
+
|
|
18
|
+
const cache = new ExpiryCache("initial", () => "string", 1000); // infering to ExpiryCache<string, () => string>
|
|
19
|
+
console.log(cache.getData()); // Outputs: initial
|
|
20
|
+
|
|
21
|
+
await new Promise((resolve) => setTimeout(resolve, 1100)); // wait for cache to expire
|
|
22
|
+
console.log(cache.isExpired); // Outputs: true
|
|
23
|
+
console.log(cache.getData()); // Outputs: null
|
|
24
|
+
|
|
25
|
+
cache.refresh();
|
|
26
|
+
console.log(cache.getData()); // Outputs: string
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### With Async Fetcher
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { ExpiryCache } from "@darco2903/expiry-cache";
|
|
33
|
+
|
|
34
|
+
async function getApiData(): Promise<string> {
|
|
35
|
+
// Simulating an API call
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
resolve("fetched data from API");
|
|
39
|
+
}, 500);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const cache = new ExpiryCache("initial data", getApiData, 5000);
|
|
44
|
+
|
|
45
|
+
await cache.refresh();
|
|
46
|
+
console.log(cache.getData()); // Outputs: fetched data from API
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### With Parameters
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { ExpiryCache } from "@darco2903/expiry-cache";
|
|
53
|
+
|
|
54
|
+
const cache = new ExpiryCache(10, (a: number, b: number) => a + b, 200);
|
|
55
|
+
|
|
56
|
+
cache.refresh(5, 7); // typed: refresh(a: number, b: number)
|
|
57
|
+
console.log(cache.getData()); // Outputs: 12
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Setting Expiry Manually
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { ExpiryCache } from "@darco2903/expiry-cache";
|
|
64
|
+
|
|
65
|
+
const cache = new ExpiryCache(0, () => 0);
|
|
66
|
+
|
|
67
|
+
cache.refresh();
|
|
68
|
+
cache.refreshExpiresAt(Date.now());
|
|
69
|
+
cache.refreshExpiresIn(1000);
|
|
70
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Time } from "@darco2903/secondthought";
|
|
2
|
+
import { ExpiryCacheBase } from "./ExpiryCacheBase.js";
|
|
3
|
+
import type { RefreshFunction } from "./types.js";
|
|
4
|
+
export declare class ExpiryCache<T, U extends RefreshFunction<T>> extends ExpiryCacheBase<T, U> {
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of ExpiryCache.
|
|
7
|
+
* @param data The initial data to be cached.
|
|
8
|
+
* @param callback The function to refresh the cached data.
|
|
9
|
+
* @param expirationTime The time in milliseconds after which the cache expires. Defaults to 60_000 (1 minute). If set to 0, the cache will never expire.
|
|
10
|
+
*/
|
|
11
|
+
constructor(data: T, callback: U, expirationTime?: number | Time);
|
|
12
|
+
/**
|
|
13
|
+
* Refreshes the cached data using the callback function.
|
|
14
|
+
*/
|
|
15
|
+
refresh(...args: Parameters<U>): void;
|
|
16
|
+
getDataOrRefresh(...args: Parameters<U>): T;
|
|
17
|
+
/**
|
|
18
|
+
* Refreshes the cached data and sets a new expiration timestamp.
|
|
19
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
20
|
+
*/
|
|
21
|
+
refreshExpiresAt(expiresAt: number | Time, ...args: Parameters<U>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Refreshes the cached data and sets a new expiration time.
|
|
24
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
25
|
+
*/
|
|
26
|
+
refreshExpiresIn(expirationTime: number | Time, ...args: Parameters<U>): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Minute } from "@darco2903/secondthought";
|
|
2
|
+
import { ExpiryCacheBase } from "./ExpiryCacheBase.js";
|
|
3
|
+
export class ExpiryCache extends ExpiryCacheBase {
|
|
4
|
+
/**
|
|
5
|
+
* Creates an instance of ExpiryCache.
|
|
6
|
+
* @param data The initial data to be cached.
|
|
7
|
+
* @param callback The function to refresh the cached data.
|
|
8
|
+
* @param expirationTime The time in milliseconds after which the cache expires. Defaults to 60_000 (1 minute). If set to 0, the cache will never expire.
|
|
9
|
+
*/
|
|
10
|
+
constructor(data, callback, expirationTime = new Minute(1)) {
|
|
11
|
+
super(data, callback, expirationTime);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Refreshes the cached data using the callback function.
|
|
15
|
+
*/
|
|
16
|
+
refresh(...args) {
|
|
17
|
+
this.setData(this.callback(...args));
|
|
18
|
+
}
|
|
19
|
+
getDataOrRefresh(...args) {
|
|
20
|
+
if (this.isExpired) {
|
|
21
|
+
this.refresh(...args);
|
|
22
|
+
}
|
|
23
|
+
return this.data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Refreshes the cached data and sets a new expiration timestamp.
|
|
27
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
28
|
+
*/
|
|
29
|
+
refreshExpiresAt(expiresAt, ...args) {
|
|
30
|
+
const expAt = this.argToMs(expiresAt);
|
|
31
|
+
this.setDataExpiresAt(this.callback(...args), expAt);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Refreshes the cached data and sets a new expiration time.
|
|
35
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
36
|
+
*/
|
|
37
|
+
refreshExpiresIn(expirationTime, ...args) {
|
|
38
|
+
const expTime = this.argToMs(expirationTime);
|
|
39
|
+
this.setDataExpiresIn(this.callback(...args), expTime);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Time } from "@darco2903/secondthought";
|
|
2
|
+
import { ExpiryCacheBase } from "./ExpiryCacheBase.js";
|
|
3
|
+
import type { RefreshFunctionAsync } from "./types.js";
|
|
4
|
+
export declare class ExpiryCacheAsync<T, U extends RefreshFunctionAsync<T>> extends ExpiryCacheBase<T, U> {
|
|
5
|
+
protected _refreshCb: Promise<T> | null;
|
|
6
|
+
get refreshing(): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of ExpiryCache.
|
|
9
|
+
* @param data The initial data to be cached.
|
|
10
|
+
* @param callback The function to refresh the cached data.
|
|
11
|
+
* @param expirationTime The time in milliseconds after which the cache expires. Defaults to 60_000 (1 minute). If set to 0, the cache will never expire.
|
|
12
|
+
*/
|
|
13
|
+
constructor(data: T, callback: U, expirationTime?: number | Time);
|
|
14
|
+
/**
|
|
15
|
+
* Refreshes the cached data using the callback function.
|
|
16
|
+
*/
|
|
17
|
+
refresh(...args: Parameters<U>): Promise<void>;
|
|
18
|
+
getDataOrRefresh(...args: Parameters<U>): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Refreshes the cached data and sets a new expiration timestamp.
|
|
21
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
22
|
+
*/
|
|
23
|
+
refreshExpiresAt(expiresAt: number | Time, ...args: Parameters<U>): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Refreshes the cached data and sets a new expiration time.
|
|
26
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
27
|
+
*/
|
|
28
|
+
refreshExpiresIn(expirationTime: number | Time, ...args: Parameters<U>): Promise<void>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Minute } from "@darco2903/secondthought";
|
|
2
|
+
import { ExpiryCacheBase } from "./ExpiryCacheBase.js";
|
|
3
|
+
export class ExpiryCacheAsync extends ExpiryCacheBase {
|
|
4
|
+
get refreshing() {
|
|
5
|
+
return this._refreshCb !== null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of ExpiryCache.
|
|
9
|
+
* @param data The initial data to be cached.
|
|
10
|
+
* @param callback The function to refresh the cached data.
|
|
11
|
+
* @param expirationTime The time in milliseconds after which the cache expires. Defaults to 60_000 (1 minute). If set to 0, the cache will never expire.
|
|
12
|
+
*/
|
|
13
|
+
constructor(data, callback, expirationTime = new Minute(1)) {
|
|
14
|
+
super(data, callback, expirationTime);
|
|
15
|
+
this._refreshCb = null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Refreshes the cached data using the callback function.
|
|
19
|
+
*/
|
|
20
|
+
async refresh(...args) {
|
|
21
|
+
if (this.refreshing) {
|
|
22
|
+
await this._refreshCb;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this._refreshCb = this.callback(...args);
|
|
26
|
+
this.setData(await this._refreshCb);
|
|
27
|
+
this._refreshCb = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async getDataOrRefresh(...args) {
|
|
31
|
+
if (this.isExpired) {
|
|
32
|
+
await this.refresh(...args);
|
|
33
|
+
}
|
|
34
|
+
return this.data;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Refreshes the cached data and sets a new expiration timestamp.
|
|
38
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
39
|
+
*/
|
|
40
|
+
async refreshExpiresAt(expiresAt, ...args) {
|
|
41
|
+
const expAt = this.argToMs(expiresAt);
|
|
42
|
+
this.setDataExpiresAt(await this.callback(...args), expAt);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Refreshes the cached data and sets a new expiration time.
|
|
46
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
47
|
+
*/
|
|
48
|
+
async refreshExpiresIn(expirationTime, ...args) {
|
|
49
|
+
const expTime = this.argToMs(expirationTime);
|
|
50
|
+
this.setDataExpiresIn(await this.callback(...args), expTime);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type Time, Millisecond } from "@darco2903/secondthought";
|
|
2
|
+
import type { RefreshFunction, RefreshFunctionAsync } from "./types.js";
|
|
3
|
+
export declare abstract class ExpiryCacheBase<T, U extends RefreshFunction<T> | RefreshFunctionAsync<T>> {
|
|
4
|
+
protected data: T;
|
|
5
|
+
protected callback: U;
|
|
6
|
+
readonly expirationTime: number;
|
|
7
|
+
/** The expiration timestamp in milliseconds. 0 means never expires, -1 means already expired or no data. */
|
|
8
|
+
protected _expiresAt: Millisecond;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the expiration timestamp in milliseconds.
|
|
11
|
+
*/
|
|
12
|
+
get expiresAt(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the cache is set to expire.
|
|
15
|
+
*/
|
|
16
|
+
get doesExpire(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the cache is expired.
|
|
19
|
+
*/
|
|
20
|
+
get isExpired(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the time to live (TTL) in milliseconds.
|
|
23
|
+
*/
|
|
24
|
+
get timeToLive(): number | null;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a number or Time object to milliseconds.
|
|
27
|
+
*/
|
|
28
|
+
protected argToMs(arg: number | Time): Millisecond;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of ExpiryCache.
|
|
31
|
+
* @param data The initial data to be cached.
|
|
32
|
+
* @param callback The function to refresh the cached data.
|
|
33
|
+
* @param expirationTime The time in milliseconds after which the cache expires. Defaults to 60_000 (1 minute). If set to 0, the cache will never expire.
|
|
34
|
+
*/
|
|
35
|
+
constructor(data: T, callback: U, expirationTime?: number | Time);
|
|
36
|
+
/**
|
|
37
|
+
* Expires the cache immediately.
|
|
38
|
+
*/
|
|
39
|
+
expire(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Sets the cache to never expire.
|
|
42
|
+
*/
|
|
43
|
+
neverExpire(): void;
|
|
44
|
+
protected expIn(ms: Millisecond): Millisecond;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the expiration timestamp based on the current time plus the given milliseconds.
|
|
47
|
+
* @param ms The time in milliseconds after which the cache should expire. If set to 0, the cache will never expire.
|
|
48
|
+
*/
|
|
49
|
+
setExpiresIn(ms: number | Time): void;
|
|
50
|
+
/**
|
|
51
|
+
* Sets the expiration timestamp to a specific time.
|
|
52
|
+
* @param timestamp The expiration timestamp in milliseconds.
|
|
53
|
+
*/
|
|
54
|
+
setExpiresAt(timestamp: number | Time): void;
|
|
55
|
+
/**
|
|
56
|
+
* Sets the cached data and resets the expiration timestamp based on the expiration time.
|
|
57
|
+
*/
|
|
58
|
+
protected setData(data: T): void;
|
|
59
|
+
/**
|
|
60
|
+
* Sets the cached data and sets a new expiration timestamp.
|
|
61
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
62
|
+
*/
|
|
63
|
+
protected setDataExpiresAt(data: T, expiresAt: Millisecond): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the cached data and sets a new expiration time.
|
|
66
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
67
|
+
*/
|
|
68
|
+
protected setDataExpiresIn(data: T, expirationTime: Millisecond): void;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the raw cached data without checking expiration.
|
|
71
|
+
*/
|
|
72
|
+
getRawData(): T;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the cached data if not expired, otherwise returns null.
|
|
75
|
+
*/
|
|
76
|
+
getData(): T | null;
|
|
77
|
+
/**
|
|
78
|
+
* Refreshes the cached data using the callback function.
|
|
79
|
+
*/
|
|
80
|
+
abstract refresh(...args: Parameters<U>): void | Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the cached data or refreshes it if expired.
|
|
83
|
+
*/
|
|
84
|
+
abstract getDataOrRefresh(...args: Parameters<U>): T | Promise<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Refreshes the cached data and sets a new expiration timestamp.
|
|
87
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
88
|
+
*/
|
|
89
|
+
abstract refreshExpiresAt(expiresAt: number | Time, ...args: Parameters<U>): void | Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Refreshes the cached data and sets a new expiration time.
|
|
92
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
93
|
+
*/
|
|
94
|
+
abstract refreshExpiresIn(expirationTime: number | Time, ...args: Parameters<U>): void | Promise<void>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Millisecond, Minute } from "@darco2903/secondthought";
|
|
2
|
+
export class ExpiryCacheBase {
|
|
3
|
+
/**
|
|
4
|
+
* Gets the expiration timestamp in milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
get expiresAt() {
|
|
7
|
+
return this._expiresAt.time;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the cache is set to expire.
|
|
11
|
+
*/
|
|
12
|
+
get doesExpire() {
|
|
13
|
+
return this._expiresAt.time !== 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the cache is expired.
|
|
17
|
+
*/
|
|
18
|
+
get isExpired() {
|
|
19
|
+
return this.doesExpire && Millisecond.now().greaterThanOrEqual(this._expiresAt);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the time to live (TTL) in milliseconds.
|
|
23
|
+
*/
|
|
24
|
+
get timeToLive() {
|
|
25
|
+
if (this.doesExpire) {
|
|
26
|
+
return Math.max(0, this._expiresAt.clone().subtract(Millisecond.now()).time);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a number or Time object to milliseconds.
|
|
32
|
+
*/
|
|
33
|
+
argToMs(arg) {
|
|
34
|
+
return typeof arg === "number" ? new Millisecond(arg) : arg.toMillisecond();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates an instance of ExpiryCache.
|
|
38
|
+
* @param data The initial data to be cached.
|
|
39
|
+
* @param callback The function to refresh the cached data.
|
|
40
|
+
* @param expirationTime The time in milliseconds after which the cache expires. Defaults to 60_000 (1 minute). If set to 0, the cache will never expire.
|
|
41
|
+
*/
|
|
42
|
+
constructor(data, callback, expirationTime = new Minute(1)) {
|
|
43
|
+
const expTime = this.argToMs(expirationTime);
|
|
44
|
+
this.data = data;
|
|
45
|
+
this._expiresAt = expTime.time === 0 ? expTime : Millisecond.now().add(expTime);
|
|
46
|
+
this.expirationTime = expTime.time;
|
|
47
|
+
this.callback = callback;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Expires the cache immediately.
|
|
51
|
+
*/
|
|
52
|
+
expire() {
|
|
53
|
+
this._expiresAt = new Millisecond(-1);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sets the cache to never expire.
|
|
57
|
+
*/
|
|
58
|
+
neverExpire() {
|
|
59
|
+
this._expiresAt = new Millisecond(0);
|
|
60
|
+
}
|
|
61
|
+
expIn(ms) {
|
|
62
|
+
return ms.time === 0 ? ms : Millisecond.now().add(ms);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sets the expiration timestamp based on the current time plus the given milliseconds.
|
|
66
|
+
* @param ms The time in milliseconds after which the cache should expire. If set to 0, the cache will never expire.
|
|
67
|
+
*/
|
|
68
|
+
setExpiresIn(ms) {
|
|
69
|
+
const t = this.argToMs(ms);
|
|
70
|
+
this._expiresAt = this.expIn(t);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sets the expiration timestamp to a specific time.
|
|
74
|
+
* @param timestamp The expiration timestamp in milliseconds.
|
|
75
|
+
*/
|
|
76
|
+
setExpiresAt(timestamp) {
|
|
77
|
+
this._expiresAt = this.argToMs(timestamp);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sets the cached data and resets the expiration timestamp based on the expiration time.
|
|
81
|
+
*/
|
|
82
|
+
setData(data) {
|
|
83
|
+
this.setDataExpiresIn(data, new Millisecond(this.expirationTime));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Sets the cached data and sets a new expiration timestamp.
|
|
87
|
+
* @param expiresAt The new expiration timestamp in milliseconds.
|
|
88
|
+
*/
|
|
89
|
+
setDataExpiresAt(data, expiresAt) {
|
|
90
|
+
this.data = data;
|
|
91
|
+
this._expiresAt = expiresAt;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sets the cached data and sets a new expiration time.
|
|
95
|
+
* @param expirationTime The new expiration time in milliseconds.
|
|
96
|
+
*/
|
|
97
|
+
setDataExpiresIn(data, expirationTime) {
|
|
98
|
+
this.setDataExpiresAt(data, this.expIn(expirationTime));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the raw cached data without checking expiration.
|
|
102
|
+
*/
|
|
103
|
+
getRawData() {
|
|
104
|
+
return this.data;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Gets the cached data if not expired, otherwise returns null.
|
|
108
|
+
*/
|
|
109
|
+
getData() {
|
|
110
|
+
if (this.isExpired) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return this.data;
|
|
114
|
+
}
|
|
115
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@darco2903/expiry-cache",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"author": "Darco2903",
|
|
5
|
+
"description": "",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"repository": {
|
|
12
|
+
"url": "https://github.com/Darco2903/expiry-cache.git"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@darco2903/secondthought": "^1.1.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@darco2903/web-common": "^0.7.0",
|
|
22
|
+
"@vitest/ui": "^3.2.4",
|
|
23
|
+
"rimraf": "^6.1.0",
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"vitest": "^3.2.4"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"test:ui": "vitest --ui",
|
|
31
|
+
"clean": "rimraf -g dist darco2903-expiry-cache-*.tgz"
|
|
32
|
+
}
|
|
33
|
+
}
|