Class SegmentCache
java.lang.Object
org.apache.jackrabbit.oak.segment.SegmentCache
A cache for
data
Segment
instances by their SegmentId
. This cache ignores bulk
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 (see SegmentId#onAccess
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default maximum weight of this cache in MB -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
clear()
Clear all segment from the cacheabstract @NotNull AbstractCacheStats
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
Record a hit in this cache's underlying statistics.
-
Field Details
-
DEFAULT_SEGMENT_CACHE_MB
public static final int DEFAULT_SEGMENT_CACHE_MBDefault maximum weight of this cache in MB- See Also:
-
-
Constructor Details
-
SegmentCache
public SegmentCache()
-
-
Method Details
-
newSegmentCache
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
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
- Returns:
- Statistics for this cache.
-
recordHit
public abstract void recordHit()Record a hit in this cache's underlying statistics. SeeSegmentId#onAccess
-