Class CacheEvictionsLogger

java.lang.Object
io.fluxcapacitor.javaclient.persisting.caching.CacheEvictionsLogger
All Implemented Interfaces:
Consumer<CacheEviction>

public class CacheEvictionsLogger extends Object implements Consumer<CacheEviction>
Logs and publishes cache eviction events as metrics.

This class listens for eviction events from a Cache and forwards them to the configured MetricsGateway. It is typically used to track cache performance and health over time, especially in distributed or memory-sensitive applications.

To activate logging for a particular cache instance, call register(Cache). This will subscribe the logger to that cache’s eviction stream.

 
 Cache cache = ...;
 CacheEvictionsLogger logger = new CacheEvictionsLogger(FluxCapacitor.get().metricsGateway());
 logger.register(cache);
 
 
See Also:
  • Constructor Details

    • CacheEvictionsLogger

      public CacheEvictionsLogger()
  • Method Details

    • register

      public Registration register(Cache cache)
      Registers this logger as an eviction listener for the given Cache.

      Eviction events will be reported to the configured MetricsGateway.

      Parameters:
      cache - The cache to monitor for evictions.
      Returns:
      A Registration that can be used to unsubscribe later.
    • accept

      public void accept(CacheEviction evictionEvent)
      Publishes the given cache eviction event to the configured metrics gateway.
      Specified by:
      accept in interface Consumer<CacheEviction>
      Parameters:
      evictionEvent - the event to report.