From d922c710a7adc3b6a39a26b92dfc3c9dda8a1cc5 Mon Sep 17 00:00:00 2001 From: Cameron Gregor Date: Fri, 9 Sep 2016 15:19:33 +1000 Subject: [PATCH] Bugfix so that you can clear a single Cache entry in userBean / peopleBean / any AbstractResourceProvider Due to incorrect logic it was impossible to clear the cache / refresh for a single entry in the cache. For example when using the userBean / peopleBean, if you tried to use peopleBean.clearCache(@UserName) it had no effect. This is because of 3 bugs in the clearCache method 1. the tests for each scope if (c==null) should actually be if (c!=null). This was preventing the code from entering into the 'remove' condition 2. The 'remove' method was incorrectly being called on the scope map e.g. sessionScope instead of the system cache that was retrieved 3. The 'remove' method was using the 'CACHE_KEY' when it should actually be using the id Note: the clearCache() method to clear the entire cache was working correctly, however I think this must have been copy/pasted to the clearCache(String) method and not correctly tidied up --- .../social/impl/AbstractResourceProvider.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.controls/src/com/ibm/xsp/extlib/social/impl/AbstractResourceProvider.java b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.controls/src/com/ibm/xsp/extlib/social/impl/AbstractResourceProvider.java index 3e61bdf..4f4e21d 100644 --- a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.controls/src/com/ibm/xsp/extlib/social/impl/AbstractResourceProvider.java +++ b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.controls/src/com/ibm/xsp/extlib/social/impl/AbstractResourceProvider.java @@ -285,9 +285,9 @@ public void clearCache(String id) { case ResourceDataProvider.SCOPE_APPLICATION: { Map map = getApplicationMap(FacesContext.getCurrentInstance().getExternalContext()); SystemCache c = (SystemCache)map.get(CACHE_KEY); - if(c==null) { - synchronized(map) { - map.remove(CACHE_KEY); + if(c!=null) { + synchronized(c) { + c.remove(id); } } return; @@ -295,9 +295,9 @@ public void clearCache(String id) { case ResourceDataProvider.SCOPE_SESSION: { Map map = TypedUtil.getSessionMap(FacesContext.getCurrentInstance().getExternalContext()); SystemCache c = (SystemCache)map.get(CACHE_KEY); - if(c==null) { - synchronized(map) { - map.remove(CACHE_KEY); + if(c!=null) { + synchronized(c) { + c.remove(id); } } return; @@ -305,9 +305,9 @@ public void clearCache(String id) { case ResourceDataProvider.SCOPE_REQUEST: { Map map = TypedUtil.getRequestMap(FacesContext.getCurrentInstance().getExternalContext()); SystemCache c = (SystemCache)map.get(CACHE_KEY); - if(c==null) { - synchronized(map) { - map.remove(CACHE_KEY); + if(c!=null) { + synchronized(c) { + c.remove(id); } } return;