From 575ee4fea9e76433666ec7480a39296156e32516 Mon Sep 17 00:00:00 2001 From: "Keith R. Gustafson" Date: Fri, 10 May 2019 12:46:40 -0700 Subject: [PATCH] Notify CacheListeners on calling refresh and removeAll - Fix bug where 2 methods failed to notify appropriate CacheListeners. - Enhance refresh() to accept vararg for the list of IDs to refresh. --- .../com/techempower/cache/EntityStore.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/gemini/src/main/java/com/techempower/cache/EntityStore.java b/gemini/src/main/java/com/techempower/cache/EntityStore.java index 6aab9661..ab1f1982 100755 --- a/gemini/src/main/java/com/techempower/cache/EntityStore.java +++ b/gemini/src/main/java/com/techempower/cache/EntityStore.java @@ -1029,14 +1029,24 @@ public T get(Class type, String methodName, Object v * * @param id the id of the object */ - public void refresh(Class type, long id) + public void refresh(Class type, long... ids) { - getGroupSafe(type).refresh(id); + getGroupSafe(type).refresh(ids); final MethodValueCache methodValueCache = methodValueCaches.get(type); if (methodValueCache != null) { - methodValueCache.update(id); + for (long id : ids) { + methodValueCache.update(id); + } + } + + // Notify the listeners. + final CacheListener[] toNotify = listeners; + for (CacheListener listener : toNotify) { + for (long id : ids) { + listener.cacheObjectExpired(type, id); + } } } @@ -1714,6 +1724,14 @@ public void removeAll(Collection objects) methodValueCache.delete(id); } } + + // Notify the listeners. + final CacheListener[] toNotify = listeners; + for (CacheListener listener : toNotify) { + for (long id : collection) { + listener.removeFromCache(type, id); + } + } } }