Interface LogCacheControl

All Superinterfaces:
LogCapability
All Known Implementing Classes:
LogCache

public interface LogCacheControl extends LogCapability
Controls the log entry cache that sits between the Raft protocol and the underlying persistent log.

When enabled, recently written entries are kept in memory so that followers can be caught up without reading from disk. When disabled, the cache becomes a transparent passthrough: all reads and writes go directly to the underlying log.

Obtain an instance via log.findCapability(LogCacheControl.class). Returns null when the log stack does not include a caching layer.

Since:
2.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the current number of entries in the cache.
    void
    Evicts all cached entries without disabling the cache.
    Returns a human-readable summary of the cache and its underlying log.
    void
    Disables caching.
    void
    enable(int maxSize)
    Enables caching with the given maximum number of entries.
    double
    Returns the fraction of cache lookups that were served from the cache.
    int
    Returns the maximum number of entries the cache will retain.
    void
    maxSize(int size)
    Sets the maximum number of entries the cache will retain.
    int
    Returns the total number of cache lookups (hits + misses).
    int
    Returns the number of times the cache has been trimmed to stay within capacity.
    void
    Resets all cache statistics (accesses, hits, trims) to zero.
    void
    Evicts the oldest entries until the cache size is within the configured maximum.
  • Method Details

    • enable

      void enable(int maxSize)
      Enables caching with the given maximum number of entries.
      Parameters:
      maxSize - the maximum number of entries to retain in the cache
    • disable

      void disable()
      Disables caching.

      The cache is cleared and all subsequent operations pass through to the underlying log.

    • clear

      void clear()
      Evicts all cached entries without disabling the cache.
    • trim

      void trim()
      Evicts the oldest entries until the cache size is within the configured maximum.
    • resetStats

      void resetStats()
      Resets all cache statistics (accesses, hits, trims) to zero.
    • maxSize

      int maxSize()
      Returns the maximum number of entries the cache will retain.
      Returns:
      the cache capacity
    • maxSize

      void maxSize(int size)
      Sets the maximum number of entries the cache will retain.
      Parameters:
      size - the new cache capacity
    • cacheSize

      int cacheSize()
      Returns the current number of entries in the cache.
      Returns:
      the number of cached entries
    • numTrims

      int numTrims()
      Returns the number of times the cache has been trimmed to stay within capacity.
      Returns:
      the trim count
    • numAccesses

      int numAccesses()
      Returns the total number of cache lookups (hits + misses).
      Returns:
      the total access count
    • hitRatio

      double hitRatio()
      Returns the fraction of cache lookups that were served from the cache.
      Returns:
      the hit ratio, between 0.0 and 1.0, or 0.0 if no accesses have occurred
    • description

      String description()
      Returns a human-readable summary of the cache and its underlying log.
      Returns:
      a description string