Commits

ha...@81dbac14-341a-0410-aa85-cbcd92e6f43e  committed 4edd63b

Don't create listener event if we have no actual listeners

  • Participants
  • Parent commits 412542f

Comments (0)

Files changed (1)

File src/core/java/com/opensymphony/oscache/base/Cache.java

      */
     public void flushAll(Date date, String origin) {
         flushDateTime = date;
-        dispatchCachewideEvent(CachewideEventType.CACHE_FLUSHED, date, origin);
+
+        if (listenerList.getListenerCount() > 0) {
+            dispatchCachewideEvent(CachewideEventType.CACHE_FLUSHED, date, origin);
+        }
     }
 
     /**
             }
         }
 
-        dispatchCacheGroupEvent(CacheEntryEventType.GROUP_FLUSHED, group, origin);
+        if (listenerList.getListenerCount() > 0) {
+            dispatchCacheGroupEvent(CacheEntryEventType.GROUP_FLUSHED, group, origin);
+        }
     }
 
     /**
                 }
             }
 
-            dispatchCachePatternEvent(CacheEntryEventType.PATTERN_FLUSHED, pattern, origin);
+            if (listenerList.getListenerCount() > 0) {
+                dispatchCachePatternEvent(CacheEntryEventType.PATTERN_FLUSHED, pattern, origin);
+            }
         } else {
             // Empty pattern, nothing to do
         }
         // in the cache!
         completeUpdate(key);
 
-        CacheEntryEvent event = new CacheEntryEvent(this, cacheEntry, origin);
+        if (listenerList.getListenerCount() > 0) {
+            CacheEntryEvent event = new CacheEntryEvent(this, cacheEntry, origin);
 
-        if (isNewEntry) {
-            dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_ADDED, event);
-        } else {
-            dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_UPDATED, event);
+            if (isNewEntry) {
+                dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_ADDED, event);
+            } else {
+                dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_UPDATED, event);
+            }
         }
     }
 
         CacheEntry cacheEntry = (CacheEntry) cacheMap.get(key);
         cacheMap.remove(key);
 
-        CacheEntryEvent event = new CacheEntryEvent(this, cacheEntry, origin);
-        dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_REMOVED, event);
+        if (listenerList.getListenerCount() > 0) {
+            CacheEntryEvent event = new CacheEntryEvent(this, cacheEntry, origin);
+            dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_REMOVED, event);
+        }
     }
 
     /**
         }
 
         // Trigger an ENTRY_FLUSHED event. [CACHE-107] Do this for all flushes.
-        CacheEntryEvent event = new CacheEntryEvent(this, entry, origin);
-        dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_FLUSHED, event);
+        if (listenerList.getListenerCount() > 0) {
+            CacheEntryEvent event = new CacheEntryEvent(this, entry, origin);
+            dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_FLUSHED, event);
+        }
     }
 }