@@ -9,7 +9,21 @@ var session = require('../session');
9
9
10
10
const plugin = new Plugin ( 50 , 'cache' , '' , 'Plugin to provide local cache.' ) ;
11
11
12
- plugin . getProblems = function ( needTranslation , cb ) {
12
+ // this function will clear all caches if needTranslation is different than stored
13
+ // it will also store the new needTranslation into cache automatically
14
+ function clearCacheIfTchanged ( needTranslation ) {
15
+ const translationConfig = cache . get ( h . KEYS . translation ) ;
16
+ if ( ! translationConfig || translationConfig [ 'useEndpointTranslation' ] != needTranslation ) {
17
+ // cache doesn't have the key => old cache version, need to update
18
+ // or cache does have the key but it contains a different value
19
+ cache . deleteAll ( ) ;
20
+ cache . set ( h . KEYS . translation , { useEndpointTranslation : needTranslation } ) ;
21
+ log . debug ( 'cache cleared: -T option changed' ) ;
22
+ }
23
+ }
24
+
25
+ plugin . getProblems = function ( needTranslation , cb ) {
26
+ clearCacheIfTchanged ( needTranslation ) ;
13
27
const problems = cache . get ( h . KEYS . problems ) ;
14
28
if ( problems ) {
15
29
log . debug ( 'cache hit: problems.json' ) ;
@@ -24,7 +38,8 @@ plugin.getProblems = function(needTranslation, cb) {
24
38
} ) ;
25
39
} ;
26
40
27
- plugin . getProblem = function ( problem , needTranslation , cb ) {
41
+ plugin . getProblem = function ( problem , needTranslation , cb ) {
42
+ clearCacheIfTchanged ( needTranslation ) ;
28
43
const k = h . KEYS . problem ( problem ) ;
29
44
const _problem = cache . get ( k ) ;
30
45
if ( _problem ) {
0 commit comments