From 8b25ab72c94bbfaa159d07005dd30de749f1ba4e Mon Sep 17 00:00:00 2001 From: Starryi Date: Sat, 28 Aug 2021 15:20:46 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-58212=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E3=80=91=E8=BF=9C=E7=A8=8B10.0=E5=8D=87?= =?UTF-8?q?=E4=B8=8A=E6=9D=A5=E7=9A=84=E5=B7=A5=E7=A8=8B=EF=BC=8C=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E6=93=8D=E4=BD=9C=E4=B8=8B=E6=96=B0=E5=BB=BA=E7=9A=84?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=A2=84=E8=A7=88500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 删除无必要的本地缓存相关的代码 2. 字段数据更新后调用invalidateCache使远程服务器数据层面缓存失效,避免服务器使用了旧的错误数据 【改动思路】 同上 --- .../mainframe/theme/AsyncThemeFetcher.java | 26 +++++-------------- .../theme/TemplateThemeManagePane.java | 26 ++++++++----------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/AsyncThemeFetcher.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/AsyncThemeFetcher.java index add47d6a0..265043283 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/AsyncThemeFetcher.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/AsyncThemeFetcher.java @@ -34,30 +34,28 @@ public class AsyncThemeFetcher { } public void submit(String themeName, AsyncThemeFetchCallback callback) { - callback.beforeCachedFetch(); + if (callback != null) { + callback.beforeCachedFetch(); + } executorService.submit(new Runnable() { @Override public void run() { if (executorService.isShutdown()) { return; } - T theme = config.cachedFetch(themeName, new TemplateThemeConfig.CacheCondition() { - @Override - public boolean shouldCacheTheme(T theme) { - return callback.shouldCache(AsyncThemeFetcher.this, theme); - } - }); + T theme = config.cachedFetch(themeName); if (executorService.isShutdown()) { return; } - callback.afterCachedFetch(theme); + if (callback != null) { + callback.afterCachedFetch(theme); + } } }); } public interface AsyncThemeFetchCallback { void beforeCachedFetch(); - boolean shouldCache(AsyncThemeFetcher fetcher, T theme); void afterCachedFetch(T theme); } @@ -68,16 +66,6 @@ public class AsyncThemeFetcher { } - @Override - public boolean shouldCache(AsyncThemeFetcher fetcher, T theme) { - // 如果Fetcher已经关闭就不放进缓存里了 - // 因为可切换工作目录,所以submit时的工作目录环境与最终获取到主题数据时的工作目录环境可能不是同一个, - // 如果仍然放进缓存中,会污染当前工作目录环境的主题缓存. - // TODO: 除了根据asyncThemeFetch的关闭情况来判断是否缓存主题,也可以更加精细的判断前后的工作目录环境是否时同一个 - // TODO: 后续看情况再优化吧. - return !fetcher.isShutdown(); - } - @Override public void afterCachedFetch(T theme) { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeManagePane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeManagePane.java index 24358a29e..8da77c378 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeManagePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeManagePane.java @@ -191,8 +191,8 @@ public class TemplateThemeManagePane extends BasicPane MenuDef menuDef = new MenuDef(Toolkit.i18nText("Fine-Design_Basic_Action_Add")); menuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH); menuDef.setRePaint(true); - menuDef.addShortCut(new AddThemeAction(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Create_Light_Theme"), config.getLightThemeName4New())); - menuDef.addShortCut(new AddThemeAction(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Create_Dark_Theme"), config.getDarkThemeName4New())); + menuDef.addShortCut(new AddThemeAction(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Create_Light_Theme"), config.getDefaultLightThemeName())); + menuDef.addShortCut(new AddThemeAction(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Create_Dark_Theme"), config.getDefaultDarkThemeName())); return menuDef; } @@ -232,31 +232,27 @@ public class TemplateThemeManagePane extends BasicPane } private class AddThemeAction extends UpdateAction { - private T prototypeTheme; + private final String prototypeThemeName; public AddThemeAction(String name, String prototypeThemeName) { setName(name); setMnemonic('R'); - asyncThemeFetcher.submit(prototypeThemeName, new AsyncThemeFetcher.AsyncThemeFetchCallbackAdapter() { - @Override - public void beforeCachedFetch() { - super.beforeCachedFetch(); - prototypeTheme = null; - } + this.prototypeThemeName = prototypeThemeName; + asyncThemeFetcher.submit(prototypeThemeName, null); + } + @Override + public void actionPerformed(ActionEvent e) { + asyncThemeFetcher.submit(prototypeThemeName, new AsyncThemeFetcher.AsyncThemeFetchCallbackAdapter() { @Override public void afterCachedFetch(T theme) { super.afterCachedFetch(theme); - prototypeTheme = theme; + createNewTheme(theme); } }); } - @Override - public void actionPerformed(ActionEvent e) { - if (prototypeTheme == null) { - return; - } + private void createNewTheme(T prototypeTheme) { Window parent = SwingUtilities.getWindowAncestor(TemplateThemeManagePane.this); TemplateThemeProfileDialog profileDialog = new TemplateThemeProfileDialog<>(parent, profilePane); try {