Skip to content

Commit 4743cbc

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8f3ea1c + f846dea commit 4743cbc

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

spec/SchemaCache.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,33 @@ describe('SchemaCache', () => {
7272
const schemaCache = new SchemaCache(cacheController, ttl);
7373
expect(schemaCache.ttl).toBe(5000);
7474
});
75+
76+
it('should use the SchemaCache ttl', async () => {
77+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
78+
79+
const anotherCacheAdapter = new InMemoryCacheAdapter({ ttl: 2000 });
80+
const anotherCacheController = new CacheController(anotherCacheAdapter, 'appId');
81+
82+
const schemaCacheTTL = 5000;
83+
const schemaCache = new SchemaCache(anotherCacheController, schemaCacheTTL, true);
84+
const schema = {
85+
className: 'Class1',
86+
};
87+
await schemaCache.setAllClasses([schema]);
88+
await sleep(4000);
89+
expect(await schemaCache.getOneSchema(schema.className)).not.toBeNull();
90+
});
91+
92+
it('should be expired', async () => {
93+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
94+
95+
const schemaCacheTTL = 2000;
96+
const schemaCache = new SchemaCache(cacheController, schemaCacheTTL, true);
97+
const schema = {
98+
className: 'Class1',
99+
};
100+
await schemaCache.setAllClasses([schema]);
101+
await sleep(3000);
102+
expect(await schemaCache.getOneSchema(schema.className)).toBeNull();
103+
});
75104
});

src/Controllers/SchemaCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class SchemaCache {
3030
if (!this.ttl) {
3131
return Promise.resolve(null);
3232
}
33-
return this.cache.put(this.prefix + MAIN_SCHEMA, schema);
33+
return this.cache.put(this.prefix + MAIN_SCHEMA, schema, this.ttl);
3434
}
3535

3636
getOneSchema(className) {

0 commit comments

Comments
 (0)