Skip to content

Commit

Permalink
Notify CacheListeners on calling refresh and removeAll (#51)
Browse files Browse the repository at this point in the history
- Fix bug where 2 methods failed to notify appropriate CacheListeners.
- Enhance refresh() to accept vararg for the list of IDs to refresh.
  • Loading branch information
k-r-g authored and msmith-techempower committed May 10, 2019
1 parent a0f5945 commit f4ae862
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions gemini/src/main/java/com/techempower/cache/EntityStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1029,14 +1029,24 @@ public <T extends Identifiable> T get(Class<T> type, String methodName, Object v
*
* @param id the id of the object
*/
public void refresh(Class<? extends Identifiable> type, long id)
public void refresh(Class<? extends Identifiable> 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);
}
}
}

Expand Down Expand Up @@ -1714,6 +1724,14 @@ public <T extends Identifiable> void removeAll(Collection<T> objects)
methodValueCache.delete(id);
}
}

// Notify the listeners.
final CacheListener[] toNotify = listeners;
for (CacheListener listener : toNotify) {
for (long id : collection) {
listener.removeFromCache(type, id);
}
}
}
}

Expand Down

0 comments on commit f4ae862

Please sign in to comment.