@@ -9,7 +9,21 @@ var session = require('../session');
99
1010const plugin = new Plugin ( 50 , 'cache' , '' , 'Plugin to provide local cache.' ) ;
1111
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 ) ;
1327 const problems = cache . get ( h . KEYS . problems ) ;
1428 if ( problems ) {
1529 log . debug ( 'cache hit: problems.json' ) ;
@@ -24,7 +38,8 @@ plugin.getProblems = function(needTranslation, cb) {
2438 } ) ;
2539} ;
2640
27- plugin . getProblem = function ( problem , needTranslation , cb ) {
41+ plugin . getProblem = function ( problem , needTranslation , cb ) {
42+ clearCacheIfTchanged ( needTranslation ) ;
2843 const k = h . KEYS . problem ( problem ) ;
2944 const _problem = cache . get ( k ) ;
3045 if ( _problem ) {
0 commit comments