@expo/entity-secondary-cache-local-memory 0.51.0 → 0.53.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EntityConfiguration, GenericSecondaryEntityCache } from '@expo/entity';
|
|
2
|
-
import {
|
|
2
|
+
import { ILocalMemoryCache } from '@expo/entity-cache-adapter-local-memory';
|
|
3
3
|
/**
|
|
4
4
|
* A local memory GenericSecondaryEntityCache.
|
|
5
5
|
*
|
|
@@ -8,5 +8,5 @@ import { LocalMemoryCache } from '@expo/entity-cache-adapter-local-memory';
|
|
|
8
8
|
* TLoadParams must be JSON stringifyable.
|
|
9
9
|
*/
|
|
10
10
|
export declare class LocalMemorySecondaryEntityCache<TFields extends Record<string, any>, TIDField extends keyof TFields, TLoadParams> extends GenericSecondaryEntityCache<TFields, TIDField, TLoadParams> {
|
|
11
|
-
constructor(entityConfiguration: EntityConfiguration<TFields, TIDField>, localMemoryCache:
|
|
11
|
+
constructor(entityConfiguration: EntityConfiguration<TFields, TIDField>, localMemoryCache: ILocalMemoryCache<TFields>);
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalMemorySecondaryEntityCache.js","sourceRoot":"","sources":["../../src/LocalMemorySecondaryEntityCache.ts"],"names":[],"mappings":";;;AAAA,yCAAgF;AAChF,+FAGiD;AAEjD;;;;;;GAMG;AACH,MAAa,+BAIX,SAAQ,oCAA2D;IACnE,YACE,mBAA2D,EAC3D,
|
|
1
|
+
{"version":3,"file":"LocalMemorySecondaryEntityCache.js","sourceRoot":"","sources":["../../src/LocalMemorySecondaryEntityCache.ts"],"names":[],"mappings":";;;AAAA,yCAAgF;AAChF,+FAGiD;AAEjD;;;;;;GAMG;AACH,MAAa,+BAIX,SAAQ,oCAA2D;IACnE,YACE,mBAA2D,EAC3D,gBAA4C;QAE5C,KAAK,CAAC,IAAI,4DAAwB,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CACpF,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CACvB,CAAC;IACJ,CAAC;CACF;AAbD,0EAaC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity-secondary-cache-local-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "Local memory secondary cache for @expo/entity",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
@@ -28,13 +28,14 @@
|
|
|
28
28
|
"author": "Expo",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@expo/entity": "^0.
|
|
32
|
-
"@expo/entity-cache-adapter-local-memory": "^0.
|
|
31
|
+
"@expo/entity": "^0.53.0",
|
|
32
|
+
"@expo/entity-cache-adapter-local-memory": "^0.53.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
+
"@isaacs/ttlcache": "^2.1.3",
|
|
35
36
|
"@jest/globals": "^30.0.1",
|
|
36
37
|
"nullthrows": "^1.1.1",
|
|
37
38
|
"typescript": "^5.9.3"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "833e2e8c55fca79fd78692a37116756a017166e4"
|
|
40
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EntityConfiguration, GenericSecondaryEntityCache } from '@expo/entity';
|
|
2
2
|
import {
|
|
3
3
|
GenericLocalMemoryCacher,
|
|
4
|
-
|
|
4
|
+
ILocalMemoryCache,
|
|
5
5
|
} from '@expo/entity-cache-adapter-local-memory';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -18,7 +18,7 @@ export class LocalMemorySecondaryEntityCache<
|
|
|
18
18
|
> extends GenericSecondaryEntityCache<TFields, TIDField, TLoadParams> {
|
|
19
19
|
constructor(
|
|
20
20
|
entityConfiguration: EntityConfiguration<TFields, TIDField>,
|
|
21
|
-
localMemoryCache:
|
|
21
|
+
localMemoryCache: ILocalMemoryCache<TFields>,
|
|
22
22
|
) {
|
|
23
23
|
super(new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache), (params) =>
|
|
24
24
|
JSON.stringify(params),
|
|
@@ -14,10 +14,12 @@ import {
|
|
|
14
14
|
ViewerContext,
|
|
15
15
|
} from '@expo/entity';
|
|
16
16
|
import {
|
|
17
|
-
|
|
17
|
+
ILocalMemoryCache,
|
|
18
18
|
LocalMemoryCacheAdapterProvider,
|
|
19
|
+
LocalMemoryCacheValue,
|
|
19
20
|
} from '@expo/entity-cache-adapter-local-memory';
|
|
20
21
|
import { StubDatabaseAdapterProvider, StubQueryContextProvider } from '@expo/entity-testing-utils';
|
|
22
|
+
import { TTLCache } from '@isaacs/ttlcache';
|
|
21
23
|
import { describe, expect, it } from '@jest/globals';
|
|
22
24
|
import nullthrows from 'nullthrows';
|
|
23
25
|
|
|
@@ -109,6 +111,14 @@ export const localMemoryTestEntityConfiguration = new EntityConfiguration<
|
|
|
109
111
|
|
|
110
112
|
const queryContextProvider = new StubQueryContextProvider();
|
|
111
113
|
|
|
114
|
+
function createTTLCache<TFields extends Record<string, any>>(): ILocalMemoryCache<TFields> {
|
|
115
|
+
return new TTLCache<string, LocalMemoryCacheValue<TFields>>({
|
|
116
|
+
max: 10000,
|
|
117
|
+
ttl: 10 * 1000, // convert to ms
|
|
118
|
+
updateAgeOnGet: true,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
112
122
|
export const createTestEntityCompanionProvider = (
|
|
113
123
|
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter(),
|
|
114
124
|
): EntityCompanionProvider => {
|
|
@@ -127,7 +137,8 @@ export const createTestEntityCompanionProvider = (
|
|
|
127
137
|
[
|
|
128
138
|
'local-memory',
|
|
129
139
|
{
|
|
130
|
-
cacheAdapterProvider:
|
|
140
|
+
cacheAdapterProvider:
|
|
141
|
+
LocalMemoryCacheAdapterProvider.createProviderWithCacheCreator(createTTLCache),
|
|
131
142
|
},
|
|
132
143
|
],
|
|
133
144
|
]),
|
|
@@ -184,7 +195,7 @@ describe(LocalMemorySecondaryEntityCache, () => {
|
|
|
184
195
|
const secondaryCacheLoader = new TestSecondaryLocalMemoryCacheLoader(
|
|
185
196
|
new LocalMemorySecondaryEntityCache(
|
|
186
197
|
localMemoryTestEntityConfiguration,
|
|
187
|
-
|
|
198
|
+
createTTLCache<LocalMemoryTestEntityFields>(),
|
|
188
199
|
),
|
|
189
200
|
LocalMemoryTestEntity.loaderWithAuthorizationResults(viewerContext),
|
|
190
201
|
);
|
|
@@ -220,7 +231,7 @@ describe(LocalMemorySecondaryEntityCache, () => {
|
|
|
220
231
|
const secondaryCacheLoader = new TestSecondaryLocalMemoryCacheLoader(
|
|
221
232
|
new LocalMemorySecondaryEntityCache(
|
|
222
233
|
localMemoryTestEntityConfiguration,
|
|
223
|
-
|
|
234
|
+
createTTLCache<LocalMemoryTestEntityFields>(),
|
|
224
235
|
),
|
|
225
236
|
LocalMemoryTestEntity.loaderWithAuthorizationResults(viewerContext),
|
|
226
237
|
);
|