@memberjunction/global 0.9.147 → 0.9.152
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/ObjectCache.d.ts +16 -1
- package/dist/ObjectCache.js +30 -5
- package/dist/ObjectCache.js.map +1 -1
- package/package.json +1 -1
package/dist/ObjectCache.d.ts
CHANGED
|
@@ -15,10 +15,25 @@ export declare class ObjectCache {
|
|
|
15
15
|
* Remove all entries from the object cache
|
|
16
16
|
*/
|
|
17
17
|
Clear(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Add a new object to the cache. If the key already exists, an exception is thrown
|
|
20
|
+
* @param key
|
|
21
|
+
* @param object
|
|
22
|
+
*/
|
|
18
23
|
Add<T>(key: string, object: T): void;
|
|
24
|
+
/**
|
|
25
|
+
* Replace an existing object in the cache with a new one. If the key does not exist, the new object is added
|
|
26
|
+
* @param key
|
|
27
|
+
* @param object
|
|
28
|
+
*/
|
|
29
|
+
Replace<T>(key: string, object: T): void;
|
|
30
|
+
/**
|
|
31
|
+
* Remove an object from the cache based on the key
|
|
32
|
+
* @param key
|
|
33
|
+
*/
|
|
19
34
|
Remove(key: string): void;
|
|
20
35
|
/**
|
|
21
|
-
*
|
|
36
|
+
* Returns an object from the cache based on the key and only if it matches the type provided in the generic
|
|
22
37
|
* @param key
|
|
23
38
|
* @returns
|
|
24
39
|
*/
|
package/dist/ObjectCache.js
CHANGED
|
@@ -25,27 +25,52 @@ class ObjectCache {
|
|
|
25
25
|
Clear() {
|
|
26
26
|
this._entries = []; // set to a blank
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Add a new object to the cache. If the key already exists, an exception is thrown
|
|
30
|
+
* @param key
|
|
31
|
+
* @param object
|
|
32
|
+
*/
|
|
28
33
|
Add(key, object) {
|
|
29
|
-
|
|
30
|
-
this._entries.
|
|
34
|
+
// make sure that if we have the key already we throw an exception
|
|
35
|
+
const idx = this._entries.findIndex((i) => i.key.trim().toLowerCase() === key.trim().toLowerCase());
|
|
36
|
+
if (idx >= 0) {
|
|
37
|
+
throw new Error(`An object with the key ${key} already exists in the cache. Remove it first before adding a new one.`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const entry = new ObjectCacheEntry(key, object);
|
|
41
|
+
this._entries.push(entry);
|
|
42
|
+
}
|
|
31
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Replace an existing object in the cache with a new one. If the key does not exist, the new object is added
|
|
46
|
+
* @param key
|
|
47
|
+
* @param object
|
|
48
|
+
*/
|
|
49
|
+
Replace(key, object) {
|
|
50
|
+
this.Remove(key); // remove the existing one if it exists
|
|
51
|
+
this.Add(key, object); // add the new one
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Remove an object from the cache based on the key
|
|
55
|
+
* @param key
|
|
56
|
+
*/
|
|
32
57
|
Remove(key) {
|
|
33
58
|
// first, see if we get a match for the index
|
|
34
59
|
const idx = this._entries.findIndex((i) => i.key.trim().toLowerCase() === key.trim().toLowerCase());
|
|
35
|
-
if (idx
|
|
60
|
+
if (idx >= 0) {
|
|
36
61
|
// now remove it
|
|
37
62
|
this._entries.splice(idx, 1);
|
|
38
63
|
}
|
|
39
64
|
}
|
|
40
65
|
/**
|
|
41
|
-
*
|
|
66
|
+
* Returns an object from the cache based on the key and only if it matches the type provided in the generic
|
|
42
67
|
* @param key
|
|
43
68
|
* @returns
|
|
44
69
|
*/
|
|
45
70
|
Find(key) {
|
|
46
71
|
// first, see if we get a match for the index
|
|
47
72
|
const idx = this._entries.findIndex((i) => i.key.trim().toLowerCase() === key.trim().toLowerCase());
|
|
48
|
-
if (idx
|
|
73
|
+
if (idx >= 0) {
|
|
49
74
|
return this._entries[idx].object;
|
|
50
75
|
}
|
|
51
76
|
return null;
|
package/dist/ObjectCache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectCache.js","sourceRoot":"","sources":["../src/ObjectCache.ts"],"names":[],"mappings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