File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -72,4 +72,33 @@ describe('SchemaCache', () => {
72
72
const schemaCache = new SchemaCache ( cacheController , ttl ) ;
73
73
expect ( schemaCache . ttl ) . toBe ( 5000 ) ;
74
74
} ) ;
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
+ } ) ;
75
104
} ) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ export default class SchemaCache {
30
30
if ( ! this . ttl ) {
31
31
return Promise . resolve ( null ) ;
32
32
}
33
- return this . cache . put ( this . prefix + MAIN_SCHEMA , schema ) ;
33
+ return this . cache . put ( this . prefix + MAIN_SCHEMA , schema , this . ttl ) ;
34
34
}
35
35
36
36
getOneSchema ( className ) {
You can’t perform that action at this time.
0 commit comments