@vicinae/api 0.9.2 → 0.9.4
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/api/cache.d.ts +7 -7
- package/dist/api/cache.js +12 -12
- package/package.json +1 -1
package/dist/api/cache.d.ts
CHANGED
|
@@ -42,12 +42,12 @@ export declare class Cache {
|
|
|
42
42
|
* @returns the data for the given key, or `undefined` if there is no data.
|
|
43
43
|
* @remarks To solely check for existence of a key, use {@link has}.
|
|
44
44
|
*/
|
|
45
|
-
get(key: string)
|
|
45
|
+
get: (key: string) => string | undefined;
|
|
46
46
|
/**
|
|
47
47
|
* @returns `true` if data for the key exists, `false` otherwise.
|
|
48
48
|
* @remarks You can use this method to check for entries without affecting the LRU access.
|
|
49
49
|
*/
|
|
50
|
-
has(key: string)
|
|
50
|
+
has: (key: string) => boolean;
|
|
51
51
|
/**
|
|
52
52
|
* @returns whether the cache is empty.
|
|
53
53
|
*/
|
|
@@ -58,25 +58,25 @@ export declare class Cache {
|
|
|
58
58
|
* This also notifies registered subscribers (see {@link subscribe}).
|
|
59
59
|
* @remarks An individual cache entry cannot be bigger than the configured capacity. If this happens, an error will be thrown.
|
|
60
60
|
*/
|
|
61
|
-
set(key: string, data: string)
|
|
61
|
+
set: (key: string, data: string) => void;
|
|
62
62
|
/**
|
|
63
63
|
* Removes the data for the given key.
|
|
64
64
|
* This also notifies registered subscribers (see {@link subscribe}).
|
|
65
65
|
* @returns `true` if data for the key was removed, `false` otherwise.
|
|
66
66
|
*/
|
|
67
|
-
remove(key: string)
|
|
67
|
+
remove: (key: string) => boolean;
|
|
68
68
|
/**
|
|
69
69
|
* Clears all stored data.
|
|
70
70
|
* This also notifies registered subscribers (see {@link subscribe}) unless the `notifySubscribers` option is set to `false`.
|
|
71
71
|
*/
|
|
72
|
-
clear(options?: {
|
|
72
|
+
clear: (options?: {
|
|
73
73
|
notifySubscribers: boolean;
|
|
74
|
-
})
|
|
74
|
+
}) => void;
|
|
75
75
|
/**
|
|
76
76
|
* Registers a new subscriber that gets notified when cache data is set or removed.
|
|
77
77
|
* @returns a function that can be called to remove the subscriber.
|
|
78
78
|
*/
|
|
79
|
-
subscribe(subscriber: Cache.Subscriber)
|
|
79
|
+
subscribe: (subscriber: Cache.Subscriber) => Cache.Subscription;
|
|
80
80
|
private keyDataPath;
|
|
81
81
|
private readKeyData;
|
|
82
82
|
private writeKeyData;
|
package/dist/api/cache.js
CHANGED
|
@@ -45,21 +45,21 @@ class Cache {
|
|
|
45
45
|
* @returns the data for the given key, or `undefined` if there is no data.
|
|
46
46
|
* @remarks To solely check for existence of a key, use {@link has}.
|
|
47
47
|
*/
|
|
48
|
-
get(key) {
|
|
48
|
+
get = (key) => {
|
|
49
49
|
const info = this.index.keys[key];
|
|
50
50
|
if (!info)
|
|
51
51
|
return undefined;
|
|
52
52
|
this.updateLRU(key);
|
|
53
53
|
this.syncIndex();
|
|
54
54
|
return this.readKeyData(key);
|
|
55
|
-
}
|
|
55
|
+
};
|
|
56
56
|
/**
|
|
57
57
|
* @returns `true` if data for the key exists, `false` otherwise.
|
|
58
58
|
* @remarks You can use this method to check for entries without affecting the LRU access.
|
|
59
59
|
*/
|
|
60
|
-
has(key) {
|
|
60
|
+
has = (key) => {
|
|
61
61
|
return typeof this.index.keys[key] !== 'undefined';
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
63
|
/**
|
|
64
64
|
* @returns whether the cache is empty.
|
|
65
65
|
*/
|
|
@@ -72,7 +72,7 @@ class Cache {
|
|
|
72
72
|
* This also notifies registered subscribers (see {@link subscribe}).
|
|
73
73
|
* @remarks An individual cache entry cannot be bigger than the configured capacity. If this happens, an error will be thrown.
|
|
74
74
|
*/
|
|
75
|
-
set(key, data) {
|
|
75
|
+
set = (key, data) => {
|
|
76
76
|
if (data.length > this.capacity) {
|
|
77
77
|
throw new Error(`A single cache entry cannot be bigger than the total capacity of the cache. The data for key ${key} is ${data.length} bytes long while the capacity is set to ${this.capacity}. You should either reduce the amount of data stored or increase the cache's capacity.`);
|
|
78
78
|
}
|
|
@@ -90,22 +90,22 @@ class Cache {
|
|
|
90
90
|
}
|
|
91
91
|
this.writeKeyData(key, data);
|
|
92
92
|
this.syncIndex();
|
|
93
|
-
}
|
|
93
|
+
};
|
|
94
94
|
/**
|
|
95
95
|
* Removes the data for the given key.
|
|
96
96
|
* This also notifies registered subscribers (see {@link subscribe}).
|
|
97
97
|
* @returns `true` if data for the key was removed, `false` otherwise.
|
|
98
98
|
*/
|
|
99
|
-
remove(key) {
|
|
99
|
+
remove = (key) => {
|
|
100
100
|
const removed = this.removeImpl(key);
|
|
101
101
|
this.syncIndex();
|
|
102
102
|
return removed;
|
|
103
|
-
}
|
|
103
|
+
};
|
|
104
104
|
/**
|
|
105
105
|
* Clears all stored data.
|
|
106
106
|
* This also notifies registered subscribers (see {@link subscribe}) unless the `notifySubscribers` option is set to `false`.
|
|
107
107
|
*/
|
|
108
|
-
clear(options) {
|
|
108
|
+
clear = (options) => {
|
|
109
109
|
const notify = options?.notifySubscribers ?? true;
|
|
110
110
|
this.removeCacheDirectory();
|
|
111
111
|
this.initIndex();
|
|
@@ -116,17 +116,17 @@ class Cache {
|
|
|
116
116
|
subscriber(key, undefined);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
}
|
|
119
|
+
};
|
|
120
120
|
/**
|
|
121
121
|
* Registers a new subscriber that gets notified when cache data is set or removed.
|
|
122
122
|
* @returns a function that can be called to remove the subscriber.
|
|
123
123
|
*/
|
|
124
|
-
subscribe(subscriber) {
|
|
124
|
+
subscribe = (subscriber) => {
|
|
125
125
|
this.subscribers.push(subscriber);
|
|
126
126
|
return () => {
|
|
127
127
|
this.subscribers.splice(this.subscribers.indexOf(subscriber), 1);
|
|
128
128
|
};
|
|
129
|
-
}
|
|
129
|
+
};
|
|
130
130
|
keyDataPath(key) {
|
|
131
131
|
return this.dataPath(this.keyHash(key));
|
|
132
132
|
}
|