From 6a1a04156c341f59e3f86462ae974eb3e3411784 Mon Sep 17 00:00:00 2001
From: Kai Reinhard <K.Reinhard@micromata.de>
Date: Fri, 14 Dec 2018 06:33:02 +0000
Subject: [PATCH] clear all caches.

---
 borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationRest.java |   13 +++++++++++++
 borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx                   |   17 ++++++++++++++++-
 borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java               |   11 ++++++++++-
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java b/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
index 37bd0b6..c3916f9 100644
--- a/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
+++ b/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -41,7 +41,7 @@
     public RepoInfo getRepoInfo(String idOrName) {
         BorgRepoConfig repoConfig = ConfigurationHandler.getConfiguration().getRepoConfig(idOrName);
         RepoInfo repoInfo = repoInfoCacheAccess.get(repoConfig.getRepo());
-        if (repoInfo == null) {
+        if (repoInfo == null ||repoInfo.getRepository() == null) {
             repoInfo = BorgCommands.info(repoConfig);
             repoInfoCacheAccess.put(repoConfig.getRepo(), repoInfo);
         }
@@ -63,7 +63,16 @@
         return repositories;
     }
 
+    public void clearAllCacheAccess(){
+        log.info("Clearing repositories cache (with list of archives)...");
+        this.repoListCacheAccess.clear();
+        clearRepoInfoCacheAccess();
+        log.info("Clearing cache with file lists of archives...");
+        this.archiveFilelistCache.removeAllCacheFiles();
+    }
+
     public void clearRepoInfoCacheAccess() {
+        log.info("Clearing repositories info cache...");
         this.repoInfoCacheAccess.clear();
     }
 
diff --git a/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationRest.java b/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationRest.java
index 325ccb4..729968f 100644
--- a/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationRest.java
+++ b/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ConfigurationRest.java
@@ -1,5 +1,6 @@
 package de.micromata.borgbutler.server.rest;
 
+import de.micromata.borgbutler.cache.ButlerCache;
 import de.micromata.borgbutler.json.JsonUtils;
 import de.micromata.borgbutler.server.ServerConfiguration;
 import de.micromata.borgbutler.server.ServerConfigurationHandler;
@@ -84,4 +85,16 @@
         }
         return getConfig(false);
     }
+
+    /**
+     * Resets the settings to default values (deletes all settings).
+     */
+    @GET
+    @Path("clearAllCaches")
+    @Produces(MediaType.APPLICATION_JSON)
+    public String clearAllCaches() {
+        log.info("Clear all caches called...");
+        ButlerCache.getInstance().clearRepoInfoCacheAccess();
+        return "OK";
+    }
 }
diff --git a/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx b/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
index 3e64086..58bcce2 100644
--- a/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
+++ b/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
@@ -77,6 +77,7 @@
         this.addDirectoryItem = this.addDirectoryItem.bind(this);
         this.removeDirectoryItem = this.removeDirectoryItem.bind(this);
         this.onResetConfiguration = this.onResetConfiguration.bind(this);
+        this.onClearAllCaches = this.onClearAllCaches.bind(this);
         this.loadConfig = this.loadConfig.bind(this);
     }
 
@@ -143,6 +144,16 @@
         }
     }
 
+    onClearAllCaches() {
+        fetch(getRestServiceUrl("configuration/clearAllCaches"), {
+            method: "GET",
+            dataType: "JSON",
+            headers: {
+                "Content-Type": "text/plain; charset=utf-8"
+            }
+        })
+    }
+
     addDirectoryItem() {
         directoryItems.push({
             index: directoryItems.length + 1,
@@ -163,12 +174,16 @@
         }
 
         if (this.state.failed) {
-            return <ErrorAlertGenericRestFailure handleClick={this.loadConfig} />;
+            return <ErrorAlertGenericRestFailure handleClick={this.loadConfig}/>;
         }
 
         return (
             <form>
                 <FormLabelField>
+                    <FormButton id={'clearCahces'} onClick={this.onClearCaches}> Clear all caches
+                    </FormButton>
+                </FormLabelField>
+                <FormLabelField>
                     <Button className={'btn-outline-primary'}
                             onClick={() => this.setState({expertSettingsOpen: !this.state.expertSettingsOpen})}>
                         <IconWarning/> <I18n name={'configuration.forExpertsOnly'}/>

--
Gitblit v1.10.0