Class CacheEvictionsLogger

java.lang.Object
io.fluxzero.sdk.persisting.caching.CacheEvictionsLogger
All Implemented Interfaces:
Consumer<io.fluxzero.common.caching.CacheEviction>

public class CacheEvictionsLogger extends Object implements Consumer<io.fluxzero.common.caching.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(Fluxzero.get().metricsGateway());
logger.register(cache);

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(io.fluxzero.common.caching.CacheEviction evictionEvent)
    Publishes the given cache eviction event to the configured metrics gateway.
    io.fluxzero.common.Registration
    register(io.fluxzero.common.caching.Cache cache)
    Registers this logger as an eviction listener for the given Cache.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Consumer

    andThen
  • Constructor Details

    • CacheEvictionsLogger

      public CacheEvictionsLogger()
  • Method Details

    • register

      public io.fluxzero.common.Registration register(io.fluxzero.common.caching.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(io.fluxzero.common.caching.CacheEviction evictionEvent)
      Publishes the given cache eviction event to the configured metrics gateway.
      Specified by:
      accept in interface Consumer<io.fluxzero.common.caching.CacheEviction>
      Parameters:
      evictionEvent - the event to report.