Class SegmentCache
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.SegmentCache
-
public abstract class SegmentCache extends Object
A cache fordata
Segment
instances by theirSegmentId
. This cache ignoresbulk
segments.Conceptually this cache serves as a 2nd level cache for segments. The 1st level cache is implemented by memoising the segment in its id (see
SegmentId#segment
. Every time an segment is evicted from this cache the memoised segment is discarded (seeSegmentId#onAccess
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SEGMENT_CACHE_MB
Default maximum weight of this cache in MB
-
Constructor Summary
Constructors Constructor Description SegmentCache()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
clear()
Clear all segment from the cacheabstract @NotNull AbstractCacheStats
getCacheStats()
abstract @NotNull Segment
getSegment(@NotNull SegmentId id, @NotNull Callable<Segment> loader)
Retrieve an segment from the cache or load it and cache it if not yet in the cache.static @NotNull SegmentCache
newSegmentCache(long cacheSizeMB)
Create a new segment cache of the given size.abstract void
putSegment(@NotNull Segment segment)
Put a segment into the cache.abstract void
recordHit()
Record a hit in this cache's underlying statistics.
-
-
-
Field Detail
-
DEFAULT_SEGMENT_CACHE_MB
public static final int DEFAULT_SEGMENT_CACHE_MB
Default maximum weight of this cache in MB- See Also:
- Constant Field Values
-
-
Method Detail
-
newSegmentCache
@NotNull public static @NotNull SegmentCache newSegmentCache(long cacheSizeMB)
Create a new segment cache of the given size. Returns an always empty cache forcacheSizeMB <= 0
.- Parameters:
cacheSizeMB
- size of the cache in megabytes.
-
getSegment
@NotNull public abstract @NotNull Segment getSegment(@NotNull @NotNull SegmentId id, @NotNull @NotNull Callable<Segment> loader) throws ExecutionException
Retrieve an segment from the cache or load it and cache it if not yet in the cache.- Parameters:
id
- the id of the segmentloader
- the loader to load the segment if not yet in the cache- Returns:
- the segment identified by
id
- Throws:
ExecutionException
- whenloader
failed to load an segment
-
putSegment
public abstract void putSegment(@NotNull @NotNull Segment segment)
Put a segment into the cache. This method does nothing forbulk
segments.- Parameters:
segment
- the segment to cache
-
clear
public abstract void clear()
Clear all segment from the cache
-
getCacheStats
@NotNull public abstract @NotNull AbstractCacheStats getCacheStats()
- Returns:
- Statistics for this cache.
-
recordHit
public abstract void recordHit()
Record a hit in this cache's underlying statistics. SeeSegmentId#onAccess
-
-