Browse Source

Добавил периодическую очистку кэша

Book Pauk 6 years ago
parent
commit
5011e23050
1 changed files with 9 additions and 1 deletions
  1. 9 1
      server/core/readerStorage.js

+ 9 - 1
server/core/readerStorage.js

@@ -6,7 +6,7 @@ const connManager = require('../db/connManager');
 class ReaderStorage {
     constructor() {
         this.storagePool = connManager.pool.readerStorage;
-        this.cache = {};
+        this.periodicCleanCache(3*3600*1000);//1 раз в 3 часа
     }
 
     async doAction(act) {
@@ -92,6 +92,14 @@ class ReaderStorage {
 
         return {state: 'success'};
     }
+
+    periodicCleanCache(timeout) {
+        this.cache = {};
+
+        setTimeout(() => {
+            this.periodicCleanCache(timeout);
+        }, timeout);
+    }
 }
 
 const readerStorage = new ReaderStorage();