public interface ICacheRecordStore
ICacheRecordStore
is the core contract providing internal functionality to
ICache
implementations on partition scope. All of the ICache methods actually
map to a method on this interface through Hazelcast's RPC mechanism. Hazelcast
Operation
is sent to the relevant partition to be executed and the final
results are returned to the callers.
For each partition, there is only one ICacheRecordStore
in the cluster.
Implementations of this interface may provide different internal data persistence like on-heap storage.
Each expirible cache entry is actually aData
, CacheRecord
pair.
Key type: always serialized form of Data
.
Value types: depend on the configuration.
CacheRecordStore
Modifier and Type | Method and Description |
---|---|
void |
clear()
clears all internal data without publishing any events
|
void |
close(boolean onShutdown)
Close is equivalent to below operations in the given order:
close resources.
unregister all listeners.
|
boolean |
contains(Data key)
Determines if this store contains an entry for the specified key.
|
void |
destroy()
Destroy is equivalent to below operations in the given order:
clear all.
close resources.
unregister all listeners.
|
void |
destroyInternals()
Like
destroy() but does not touch state on other services
like event journal service. |
void |
disposeDeferredBlocks() |
void |
evictExpiredEntries(int percentage)
Do expiration operations.
|
boolean |
evictIfRequired()
Evict cache record store if eviction is required.
|
CacheEntryIterationResult |
fetchEntries(int tableIndex,
int size)
Starting from the provided table index, a set of entries are returned with a maximum size of
size |
CacheKeyIterationResult |
fetchKeys(int tableIndex,
int size)
Starting from the provided table index, a set of keys are returned with a maximum size of
size |
Object |
get(Data key,
javax.cache.expiry.ExpiryPolicy expiryPolicy)
Gets the value to which the specified key is mapped,
or
null if this cache contains no mapping for the key. |
MapEntries |
getAll(Set<Data> keySet,
javax.cache.expiry.ExpiryPolicy expiryPolicy)
Gets a collection of entries from the store, returning them as
Map of the values associated with the set of keys requested. |
Object |
getAndPut(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String caller,
int completionId)
Associates the specified value with the specified key in this cache,
returning an existing value if one existed.
|
Object |
getAndRemove(Data key,
String caller,
int completionId)
Atomically removes the entry for a key only if it is currently mapped to some
value.
|
Object |
getAndReplace(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String caller,
int completionId)
Atomically replaces the value for a given key if and only if there is a
value currently mapped by the key.
|
CacheStatisticsImpl |
getCacheStats()
Gets the Cache statistics associated with this
CacheService . |
CacheConfig |
getConfig()
Gets the configuration of the cache that this store belongs to.
|
InvalidationQueue<ExpiredKey> |
getExpiredKeysQueue() |
Object |
getExpiryPolicy(Data key) |
String |
getName()
Gets the name of the distributed object name of the cache.
|
ObjectNamespace |
getObjectNamespace()
Returns
ObjectNamespace associated with this record store. |
int |
getPartitionId() |
Map<Data,CacheRecord> |
getReadOnlyRecords()
Returns a readonly map of the internal key value store.
|
CacheRecord |
getRecord(Data key)
Gets internal record of the store by key.
|
void |
init()
Initializes record store.
|
Object |
invoke(Data key,
javax.cache.processor.EntryProcessor entryProcessor,
Object[] arguments,
int completionId)
Invokes an
EntryProcessor against the Cache.Entry specified by
the provided key. |
boolean |
isExpirable() |
boolean |
isWanReplicationEnabled()
Determines whether wan replication is enabled or not for this record store.
|
Set<Data> |
loadAll(Set<Data> keys,
boolean replaceExistingValues)
Synchronously loads the specified entries into the cache using the
configured
CacheLoader for the given keys. |
CacheRecord |
merge(CacheEntryView<Data,Data> cacheEntryView,
CacheMergePolicy mergePolicy,
String caller,
String origin,
int completionId,
CallerProvenance callerProvenance)
Merges the given
CacheEntryView via the given CacheMergePolicy . |
CacheRecord |
merge(SplitBrainMergeTypes.CacheMergeTypes mergingEntry,
SplitBrainMergePolicy<Data,SplitBrainMergeTypes.CacheMergeTypes> mergePolicy,
CallerProvenance callerProvenance)
Merges the given
SplitBrainMergeTypes.CacheMergeTypes via the given SplitBrainMergePolicy . |
CacheRecord |
put(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String caller,
int completionId)
Associates the specified value with the specified key in this cache,
returning an existing value if one existed.
|
boolean |
putIfAbsent(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String caller,
int completionId)
Removes the mapping for a key from this cache if it is present.
|
void |
putRecord(Data key,
CacheRecord record,
boolean updateJournal)
Associates the specified record with the specified key.
|
boolean |
remove(Data key,
Object value,
String caller,
String origin,
int completionId)
Atomically removes the mapping for a key only if currently mapped to the
given value.
|
boolean |
remove(Data key,
String caller,
String origin,
int completionId) |
boolean |
remove(Data key,
String caller,
String origin,
int completionId,
CallerProvenance provenance)
Removes the mapping for a key from this cache if it is present.
|
void |
removeAll(Set<Data> keys,
int completionId)
records of keys will be deleted one by one and will publish a REMOVE event
for each key.
|
CacheRecord |
removeRecord(Data key)
Removes the record for a key.
|
boolean |
replace(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String caller,
int completionId)
Atomically replaces the entry for a key only if currently mapped to some
value.
|
boolean |
replace(Data key,
Object oldValue,
Object newValue,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String caller,
int completionId)
Atomically replaces the entry for a key only if currently mapped to a
given value.
|
void |
reset()
Resets the record store to it's initial state.
|
void |
sampleAndForceRemoveEntries(int count) |
boolean |
setExpiryPolicy(Collection<Data> keys,
Object expiryPolicy,
String source)
Sets expiry policy for the records with given keys if and only if there is a
value currently mapped by the key
|
int |
size()
Calculates the entry size of this store which reflects the partition size of the cache.
|
Object get(Data key, javax.cache.expiry.ExpiryPolicy expiryPolicy)
null
if this cache contains no mapping for the key.
If the cache is configured to use read-through, and get would return null
because the entry is missing from the cache, the Cache's CacheLoader
is called in an attempt to load the entry.
key
- the key whose associated value is to be returned.expiryPolicy
- custom expiry policy or null to use configured default value.CacheRecord put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, int completionId)
If the cache previously contained a mapping for
the key, the old value is replaced by the specified value. (A cache
c is said to contain a mapping for a key k if and only
if c.contains(k)
would return
true.)
The previous value is returned, or null if there was no value associated with the key previously.
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.caller
- UUID of the calling node or client.CacheRecord
(added as new record or updated). null
if record has expired.Object getAndPut(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, int completionId)
If the cache previously contained a mapping for
the key, the old value is replaced by the specified value. (A cache
c is said to contain a mapping for a key k if and only
if c.contains(k)
would return
true.)
The previous value is returned, or null if there was no value associated with the key previously.
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.caller
- UUID of the calling node or client.boolean putIfAbsent(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, int completionId)
More formally, if this cache contains a mapping from key k to
value v such that
(key==null ? k==null : key.equals(k))
, that mapping is removed.
(The cache can contain at most one such mapping.)
Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key.
The cache will not contain a mapping for the specified key once the call returns.
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.caller
- UUID of the calling node or client.Object getAndRemove(Data key, String caller, int completionId)
This is equivalent to:
if (cache.containsKey(key)) {
V oldValue = cache.get(key);
cache.remove(key);
return oldValue;
} else {
return null;
}
except that the action is performed atomically.key
- key with which the specified value is associated.caller
- UUID of the calling node or client.boolean remove(Data key, String caller, String origin, int completionId, CallerProvenance provenance)
More formally, if this cache contains a mapping from key k to
value v such that
(key==null ? k==null : key.equals(k))
, that mapping is removed.
(The cache can contain at most one such mapping.)
Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key.
The cache will not contain a mapping for the specified key once the call returns.
key
- key whose mapping is to be removed from the cache.caller
- UUID of the calling node or client.origin
- Source of the callcompletionId
- User generated id which shall be received as a field of the cache event upon completion of
the request in the cluster.provenance
- caller operation provenanceboolean remove(Data key, Object value, String caller, String origin, int completionId)
This is equivalent to:
if (cache.containsKey(key) && equals(cache.get(key), oldValue) {
cache.remove(key);
return true;
} else {
return false;
}
except that the action is performed atomically.key
- key whose mapping is to be removed from the cache.value
- value expected to be associated with the specified key.caller
- UUID of the calling node or client.origin
- Source of the callcompletionId
- User generated id which shall be received as a field of the cache event upon completion of
the request in the cluster.boolean replace(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, int completionId)
This is equivalent to
if (cache.containsKey(key)) {
cache.put(key, value);
return true;
} else {
return false;
}
except that the action is performed atomically.key
- the key with which the specified value is associated.value
- the value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.caller
- UUID of the calling node or client.boolean replace(Data key, Object oldValue, Object newValue, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, int completionId)
This is equivalent to:
if (cache.containsKey(key) && equals(cache.get(key), oldValue)) {
cache.put(key, newValue);
return true;
} else {
return false;
}
except that the action is performed atomically.key
- key with which the specified value is associated.oldValue
- value expected to be associated with the specified key.newValue
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.caller
- UUID of the calling node or client.Object getAndReplace(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, int completionId)
This is equivalent to
if (cache.containsKey(key)) {
V oldValue = cache.get(key);
cache.put(key, value);
return oldValue;
} else {
return null;
}
except that the action is performed atomically.key
- key with which the specified value is associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.caller
- uuid of the calling node or client.boolean setExpiryPolicy(Collection<Data> keys, Object expiryPolicy, String source)
keys
- keys for the entriesexpiryPolicy
- custom expiry policy or null to use configured default valueboolean contains(Data key)
More formally, returns true if and only if this store contains a mapping for a key k such that key.equals(k) (There can be at most one such mapping.)
key
- key whose presence in this store is to be tested.MapEntries getAll(Set<Data> keySet, javax.cache.expiry.ExpiryPolicy expiryPolicy)
Map
of the values associated with the set of keys requested.
If the cache is configured read-through, and a get for a key would
return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an
entry cannot be loaded for a given key, the key will not be present in
the returned Map.
keySet
- keys whose associated values are to be returned.expiryPolicy
- custom expiry policy or null to use configured default value.int size()
void clear()
void reset()
void removeAll(Set<Data> keys, int completionId)
keys
- set of keys to be cleaned.void init()
void close(boolean onShutdown)
void destroy()
clear()
,
close(boolean)
void destroyInternals()
destroy()
but does not touch state on other services
like event journal service.CacheConfig getConfig()
CacheConfig
String getName()
Map<Data,CacheRecord> getReadOnlyRecords()
boolean isExpirable()
CacheRecord getRecord(Data key)
key
- the key to the entry.CacheRecord
instance mapped.void putRecord(Data key, CacheRecord record, boolean updateJournal)
key
- the key to the entry.record
- the value to be associated with the specified key.updateJournal
- when true an event is appended to related event-journalCacheRecord removeRecord(Data key)
key
- the key to the entry.CacheKeyIterationResult fetchKeys(int tableIndex, int size)
size
tableIndex
- initial table index.size
- maximum key set size.CacheKeyIterationResult
which wraps keys and last tableIndex.CacheEntryIterationResult fetchEntries(int tableIndex, int size)
size
tableIndex
- initial table index.size
- maximum entry set size.CacheEntryIterationResult
which wraps entries and last tableIndex.Object invoke(Data key, javax.cache.processor.EntryProcessor entryProcessor, Object[] arguments, int completionId)
EntryProcessor
against the Cache.Entry
specified by
the provided key. If an Cache.Entry
does not exist for the specified key,
an attempt is made to load it (if a loader is configured) or a surrogate
Cache.Entry
, consisting of the key with a null value is used instead.
key
- the key of the entry.entryProcessor
- the EntryProcessor
to be invoked.arguments
- additional arguments to be passed to the
EntryProcessor
.EntryProcessor
implementation.Set<Data> loadAll(Set<Data> keys, boolean replaceExistingValues)
CacheLoader
for the given keys.
If an entry for a key already exists in the cache, a value will be loaded
if and only if replaceExistingValues
is true. If no loader
is configured for the cache, no objects will be loaded.
keys
- the keys to be loaded.replaceExistingValues
- when true, existing values in the cache will
be replaced by those loaded from a CacheLoader.CacheStatisticsImpl getCacheStats()
CacheService
.CacheStatisticsImpl
cache statistics.boolean evictIfRequired()
Eviction logic is handled as specified EvictionPolicy
in CacheConfig
for this record store
void sampleAndForceRemoveEntries(int count)
boolean isWanReplicationEnabled()
ObjectNamespace getObjectNamespace()
ObjectNamespace
associated with this record store.CacheRecord merge(SplitBrainMergeTypes.CacheMergeTypes mergingEntry, SplitBrainMergePolicy<Data,SplitBrainMergeTypes.CacheMergeTypes> mergePolicy, CallerProvenance callerProvenance)
SplitBrainMergeTypes.CacheMergeTypes
via the given SplitBrainMergePolicy
.mergingEntry
- the SplitBrainMergeTypes.CacheMergeTypes
instance to mergemergePolicy
- the SplitBrainMergePolicy
instance to applycallerProvenance
- CacheRecord
if merge is applied, otherwise null
CacheRecord merge(CacheEntryView<Data,Data> cacheEntryView, CacheMergePolicy mergePolicy, String caller, String origin, int completionId, CallerProvenance callerProvenance)
CacheEntryView
via the given CacheMergePolicy
.cacheEntryView
- the CacheEntryView
instance to mergemergePolicy
- the CacheMergePolicy
instance to applycaller
- the UUID of the callerorigin
- source of the callcompletionId
- User generated id which shall be received as a field of the cache event upon completion of
the request in the cluster.callerProvenance
- CacheRecord
if merge is applied, otherwise null
int getPartitionId()
void evictExpiredEntries(int percentage)
percentage
- of max expirables according to the record store size.InvalidationQueue<ExpiredKey> getExpiredKeysQueue()
void disposeDeferredBlocks()
Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.