Fix schemaCacheTTL ParseServerOption is not working (#7138)
* Add Test case for checking SchemaCacheTTL * Fix schemaCacheTTL not working issue * Add Test case for TTL expires Co-authored-by: Roach Chang <roach.chang@aoitek.com>
This commit is contained in:
@@ -72,4 +72,33 @@ describe('SchemaCache', () => {
|
|||||||
const schemaCache = new SchemaCache(cacheController, ttl);
|
const schemaCache = new SchemaCache(cacheController, ttl);
|
||||||
expect(schemaCache.ttl).toBe(5000);
|
expect(schemaCache.ttl).toBe(5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use the SchemaCache ttl', async () => {
|
||||||
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
const anotherCacheAdapter = new InMemoryCacheAdapter({ ttl: 2000 });
|
||||||
|
const anotherCacheController = new CacheController(anotherCacheAdapter, 'appId');
|
||||||
|
|
||||||
|
const schemaCacheTTL = 5000;
|
||||||
|
const schemaCache = new SchemaCache(anotherCacheController, schemaCacheTTL, true);
|
||||||
|
const schema = {
|
||||||
|
className: 'Class1',
|
||||||
|
};
|
||||||
|
await schemaCache.setAllClasses([schema]);
|
||||||
|
await sleep(4000);
|
||||||
|
expect(await schemaCache.getOneSchema(schema.className)).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be expired', async () => {
|
||||||
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
const schemaCacheTTL = 2000;
|
||||||
|
const schemaCache = new SchemaCache(cacheController, schemaCacheTTL, true);
|
||||||
|
const schema = {
|
||||||
|
className: 'Class1',
|
||||||
|
};
|
||||||
|
await schemaCache.setAllClasses([schema]);
|
||||||
|
await sleep(3000);
|
||||||
|
expect(await schemaCache.getOneSchema(schema.className)).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default class SchemaCache {
|
|||||||
if (!this.ttl) {
|
if (!this.ttl) {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
return this.cache.put(this.prefix + MAIN_SCHEMA, schema);
|
return this.cache.put(this.prefix + MAIN_SCHEMA, schema, this.ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOneSchema(className) {
|
getOneSchema(className) {
|
||||||
|
|||||||
Reference in New Issue
Block a user