Interface LogCacheControl
- All Superinterfaces:
LogCapability
- All Known Implementing Classes:
LogCache
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 TypeMethodDescriptionintReturns the current number of entries in the cache.voidclear()Evicts all cached entries without disabling the cache.Returns a human-readable summary of the cache and its underlying log.voiddisable()Disables caching.voidenable(int maxSize) Enables caching with the given maximum number of entries.doublehitRatio()Returns the fraction of cache lookups that were served from the cache.intmaxSize()Returns the maximum number of entries the cache will retain.voidmaxSize(int size) Sets the maximum number of entries the cache will retain.intReturns the total number of cache lookups (hits + misses).intnumTrims()Returns the number of times the cache has been trimmed to stay within capacity.voidResets all cache statistics (accesses, hits, trims) to zero.voidtrim()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
-