public class SegmentCache extends Object
Segment
instances by their SegmentId
.
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.unloaded()
).
As a consequence this cache is actually only queried for segments it does not contain,
which are then loaded through the loader passed to getSegment(SegmentId, Callable)
.
This behaviour is eventually reflected in the cache statistics (see getCacheStats()
),
which always reports a miss rate
of 1.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SEGMENT_CACHE_MB |
Constructor and Description |
---|
SegmentCache(long cacheSizeMB)
Create a new segment cache of the given size.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all segment from the cache
|
org.apache.jackrabbit.oak.cache.CacheStats |
getCacheStats()
See the class comment regarding some peculiarities of this cache's statistics
|
Segment |
getSegment(SegmentId id,
Callable<Segment> loader)
Retrieve an segment from the cache or load it and cache it if not yet in the cache.
|
void |
putSegment(Segment segment)
Put a segment into the cache
|
public static final int DEFAULT_SEGMENT_CACHE_MB
public SegmentCache(long cacheSizeMB)
cacheSizeMB
- size of the cache in megabytes.@Nonnull public Segment getSegment(@Nonnull SegmentId id, @Nonnull Callable<Segment> loader) throws ExecutionException
id
- the id of the segmentloader
- the loader to load the segment if not yet in the cacheid
ExecutionException
- when loader
failed to load an segmentpublic void putSegment(@Nonnull Segment segment)
segment
- the segment to cachepublic void clear()
@Nonnull public org.apache.jackrabbit.oak.cache.CacheStats getCacheStats()
Copyright © 2012-2016 The Apache Software Foundation. All Rights Reserved.