Click or drag to resize

LocalCache Class

Oracle® Fusion Middleware .NET API Reference for Oracle Coherence
14c (14.1.1.0)
F23534-02
A local in-memory cache implementation.
Inheritance Hierarchy

Namespace:  Tangosol.Net.Cache
Assembly:  Coherence (in Coherence.dll) Version: 14.1.1.14 (14.1.1.14)
Syntax
C#
public class LocalCache : SynchronizedDictionary, IConfigurableCache, 
	IObservableCache, IConcurrentCache, IQueryCache, IInvocableCache, ICache, 
	IDictionary, ICollection, IEnumerable

The LocalCache type exposes the following members.

Constructors
  NameDescription
Public methodLocalCache
Construct the cache manager.
Public methodLocalCache(Int32)
Construct the cache manager.
Public methodLocalCache(Int32, Int32)
Construct the cache manager.
Public methodLocalCache(Int32, Int32, Double)
Construct the cache manager.
Public methodLocalCache(Int32, Int32, ICacheLoader)
Construct the cache manager.
Top
Properties
  NameDescription
Public propertyCacheHits
Gets the rough number of cache hits since the cache statistics were last reset.
Public propertyCacheLoader
Gets or sets the loader used by this LocalCache.
Public propertyCacheMisses
Gets the rough number of cache misses since the cache statistics were last reset.
Public propertyCacheStatistics
Gets the ICacheStatistics for this cache.
Protected propertyCacheStore
Determine the store used by this LocalCache, if any.
Public propertyCalculatorType
Gets or sets the current unit calculator type for the cache.
Public propertyCount
Gets the number of elements contained in the ICache.
(Overrides SynchronizedDictionaryCount.)
Protected propertyCurrentKeyMask
Gets or sets the current key mask for the current thread.
Public propertyDelegate
Return the delegate IDictionary.
(Inherited from SynchronizedDictionary.)
Public propertyEntries
Get a collection of ICacheEntry instances within the cache.
Public propertyEvictionPolicy
Determine the current external eviction policy, if any.
Public propertyEvictionType
Gets or sets the current eviction type.
Public propertyExpiryDelay
Gets or sets the "time to live" for each individual cache entry.
Public propertyFlushDelay
Gets or sets the delay between cache flushes.
Public propertyFlushTime
Gets or sets the date/time offset in milliseconds at which the next cache flush is scheduled.
Public propertyHighUnits
Gets or sets the limit of the cache size in units.
Public propertyHitProbability
Gets the rough probability (0 <= p <= 1) that any particular "get" invocation will be satisfied by an existing entry in the cache, based on the statistics collected since the last reset of the cache statistics.
Protected propertyIndexMap
The index IDictionary used by this LocalCache.
Public propertyIsFixedSize
Get a value indicating whether this dictionary has a fixed size.
(Inherited from SynchronizedDictionary.)
Public propertyIsReadLockHeld
Determines whether or not the current thread holds a read lock.
(Inherited from SynchronizedDictionary.)
Public propertyIsReadOnly
Get a value indicating whether this dictionary is read-only.
(Inherited from SynchronizedDictionary.)
Public propertyIsSynchronized
Gets a value indicating whether access to this dictionary is thread-safe.
(Inherited from SynchronizedDictionary.)
Public propertyIsWriteLockHeld
Determines whether or not the current thread holds the write lock.
(Inherited from SynchronizedDictionary.)
Public propertyItem
Gets or sets the element with the specified key.
(Overrides SynchronizedDictionaryItemObject.)
Public propertyKeys
Get the keys collection.
(Overrides SynchronizedDictionaryKeys.)
Public propertyLowUnits
Gets or sets the point to which the cache will shrink when it prunes.
Public propertyPruneLevel
The percentage of the total number of units that will remain after the cache manager prunes the cache.
Protected propertyStorage
Get underlying cache storage.
Public propertySyncRoot
Get an object that can be used to synchronize access to this dictionary.
(Inherited from SynchronizedDictionary.)
Public propertyUnitCalculator
Gets or sets the current external unit calculator, if any.
Public propertyUnits
Gets the number of units that the cache currently stores.
Public propertyValues
Get the values collection.
(Overrides SynchronizedDictionaryValues.)
Top
Methods
  NameDescription
Public methodAcquireReadLock
Acquire a read lock.
(Inherited from SynchronizedDictionary.)
Public methodAcquireReadLock(Int32)
Acquire a read lock.
(Inherited from SynchronizedDictionary.)
Public methodAcquireWriteLock
Acquire a write lock.
(Inherited from SynchronizedDictionary.)
Public methodAcquireWriteLock(Int32)
Acquire a write lock.
(Inherited from SynchronizedDictionary.)
Public methodAdd
Adds an element with the provided key and value to the cache.
(Overrides SynchronizedDictionaryAdd(Object, Object).)
Public methodAddCacheListener(ICacheListener)
Add a standard cache listener that will receive all events (inserts, updates, deletes) that occur against the cache, with the key, old-value and new-value included.
Public methodAddCacheListener(ICacheListener, Object, Boolean)
Add a cache listener for a specific key.
Public methodAddCacheListener(ICacheListener, IFilter, Boolean)
Add a cache listener that receives events based on a filter evaluation.
Public methodAddIndex
Add an index to this IQueryCache.
Protected methodAddInternal
Add new cache entry and raise Inserted event if necessary.
Protected methodAdjustUnits
Adjust current size.
Public methodAggregate(ICollection, IEntryAggregator)
Perform an aggregating operation against the entries specified by the passed keys.
Public methodAggregate(IFilter, IEntryAggregator)
Perform an aggregating operation against the collection of entries that are selected by the given IFilter.
Protected methodCheckFlush
Flush the cache if it needs to be flushed.
Protected methodCheckSize
Check if the cache is too big, and if it is prune it by discarding the lowest priority cache entries.
Public methodClear
Removes all elements from the ICache object.
(Overrides SynchronizedDictionaryClear.)
Protected methodClearInternal
Utility method to support clear and truncation operations.
Protected methodConfigureEviction
Configure the eviction type and policy.
Protected methodConfigureUnitCalculator
Configure the unit calculator type and implementation.
Public methodContains
Determines whether the object contains an element with the specified key.
(Overrides SynchronizedDictionaryContains(Object).)
Public methodContainsKey
Determines whether the IDictionary object contains an element with the specified key.
Public methodContainsValue
Determines whether the IDictionary object contains an element with the specified value.
Public methodCopyTo
Copies the elements of the IDictionary to an Array, starting at a particular index.
(Overrides SynchronizedDictionaryCopyTo(Array, Int32).)
Protected methodCreateEntry
Creates an ICacheEntry.
Protected methodDispatchEvent
Dispatch the passed event.
Protected methodEnsureEntry
Protected methodEnsureEntryCollection
Create an array of LocalCacheEntry objects for the specified ICache and the keys collection.
Protected methodEnsureIndexMap
Obtain the IDictionary of indexes maintained by this cache.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodEvict
Evict all entries from the cache that are no longer valid, and potentially prune the cache size if the cache is size-limited and its size is above the caching low water mark.
Public methodEvict(Object)
Evict a specified key from the cache, as if it had expired from the cache.
Public methodEvictAll
Evict the specified keys from the cache, as if they had each expired from the cache.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetAll
Get the values for all the specified keys, if they are in the cache.
Public methodGetCacheEntry
Locate a cache entry in the cache based on its key.
Public methodGetEntries(IFilter)
Return a collection of the entries contained in this cache that satisfy the criteria expressed by the filter.
Public methodGetEntries(IFilter, IComparer)
Return a collection of the entries contained in this cache that satisfy the criteria expressed by the filter.
Public methodGetEntry
Protected methodGetEntryInternal
Public methodGetEnumerator
Returns an ICacheEnumerator object for the ICache instance.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetKeys
Return a collection of the keys contained in this cache for entries that satisfy the criteria expressed by the filter.
Public methodGetObjectData
Populates SerializationInfo with the data needed to serialize this object.
(Inherited from SynchronizedDictionary.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetValues(IFilter)
Return a collection of the values contained in this cache for entries that satisfy the criteria expressed by the filter.
Public methodGetValues(IFilter, IComparer)
Return a collection of the values contained in this cache for entries that satisfy the criteria expressed by the filter.
Protected methodHasListeners
Determine if the LocalCache has any listeners at all.
Public methodInsert(Object, Object)
Associates the specified value with the specified key in this cache.
Public methodInsert(Object, Object, Int64)
Associates the specified value with the specified key in this cache.
Public methodInsertAll
Copies all of the mappings from the specified dictionary to this cache (optional operation).
Protected methodInstantiateCacheEnumerator
Factory method for cache enumerator.
Protected methodInstantiateCacheEvent
Factory pattern: instantiate a new CacheEventArgs corresponding to the specified parameters.
Protected methodInstantiateEntriesCollection
Factory method that creates virtual collection of cache entries.
Protected methodInstantiateInternalListener
Factory pattern: Instantiate an internal ICacheListener to listen to this cache and report changes to the ICacheStore.
Protected methodInstantiateKeysCollection
Factory method that creates virtual collection of cache keys.
Protected methodInstantiateValuesCollection
Factory method that creates virtual collection of cache values.
Public methodInvoke
Invoke the passed IEntryProcessor against the entry specified by the passed key, returning the result of the invocation.
Public methodInvokeAll(ICollection, IEntryProcessor)
Invoke the passed IEntryProcessor against the entries specified by the passed keys, returning the result of the invocation for each.
Public methodInvokeAll(IFilter, IEntryProcessor)
Invoke the passed IEntryProcessor against the set of entries that are selected by the given IFilter, returning the result of the invocation for each.
Protected methodIsFlushRequired
Check if the cache needs to be flushed.
Public methodLoad
Indicates to the cache that the specified key should be loaded into the cache, if it is not already in the cache.
Public methodLoadAll
Indicates to the cache that it should load data from its loader to fill the cache; this is sometimes referred to as "pre-loading" or "warming" a cache.
Public methodLoadAll(ICollection)
Indicates to the cache that the specified keys should be loaded into the cache, if they are not already in the cache.
Public methodLock(Object)
Attempt to lock the specified item and return immediately.
Public methodLock(Object, Int64)
Attempt to lock the specified item within the specified period of time.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodPeek
Checks for a valid entry corresponding to the specified key in the cache, and returns the corresponding value if it is.
Public methodPeekAll
Checks for a valid entry corresponding to each specified key in the cache, and places the corresponding value in the returned dictionary if it is.
Protected methodPeekEntryInternal
Protected methodPrune
Prune the cache by discarding the lowest priority cache entries.
Public methodReleaseReadLock
Release a read lock.
(Inherited from SynchronizedDictionary.)
Public methodReleaseWriteLock
Release a write lock.
(Inherited from SynchronizedDictionary.)
Public methodRemove
Removes the element with the specified key from the ICache object.
(Overrides SynchronizedDictionaryRemove(Object).)
Public methodRemoveCacheListener(ICacheListener)
Remove a standard cache listener that previously signed up for all events.
Public methodRemoveCacheListener(ICacheListener, Object)
Remove a cache listener that previously signed up for events about a specific key.
Public methodRemoveCacheListener(ICacheListener, IFilter)
Remove a cache listener that previously signed up for events based on a filter evaluation.
Protected methodRemoveExpired
Remove an entry because it has expired.
Public methodRemoveIndex
Remove an index from this IQueryCache.
Protected methodRemoveInternal
Remove an entry.
Public methodResetHitStatistics
Reset the cache statistics.
Protected methodScheduleFlush
Schedule the next flush.
Public methodToString
Returns a string representation of this LocalCache object.
(Overrides ObjectToString.)
Public methodTruncate
Removes all mappings from this map.
Public methodUnlock
Unlock the specified item.
Top
Fields
  NameDescription
Public fieldStatic memberDEFAULT_EXPIRE
By default, the cache entries never expire.
Public fieldStatic memberDEFAULT_FLUSH
By default, expired cache entries are flushed on a minute interval.
Protected fieldDEFAULT_KEY_MASK
The default key mask that ignores nothing.
Public fieldStatic memberDEFAULT_PRUNE
By default, when the cache prunes, it reduces its entries by 25%, meaning it retains 75% (.75) of its entries.
Public fieldStatic memberDEFAULT_UNITS
By default, the cache size (in units) is infinite.
Protected fieldm_avgTouch
For a prune cycle, this value is the average number of touches that an entry should have. This value is used by the hybrid eviction policy.
Protected fieldm_dict
Wrapped, non-thread safe dictionary.
(Inherited from SynchronizedDictionary.)
Protected fieldm_lastPrune
The last time that a prune was run. This value is used by the hybrid eviction policy.
Top
Extension Methods
  NameDescription
Public Extension MethodGetOrDefault
Returns the value to which the specified key is mapped, or the defaultValue if this cache contains no mapping for the key.
(Defined by InvocableCacheEx.)
Public Extension MethodInsertIfAbsent
If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.
(Defined by InvocableCacheEx.)
Public Extension MethodRemove
Removes the entry for the specified key only if it is currently mapped to the specified value.
(Defined by InvocableCacheEx.)
Public Extension MethodReplace(Object, Object)Overloaded.
Replaces the entry for the specified key only if it is currently mapped to some value.
(Defined by InvocableCacheEx.)
Public Extension MethodReplace(Object, Object, Object)Overloaded.
Replaces the entry for the specified key only if currently mapped to the specified value.
(Defined by InvocableCacheEx.)
Top
Remarks

The implementation is thread safe and uses a combination of Most Recently Used (MRU) and Most Frequently Used (MFU) caching strategies.

The cache is size-limited, which means that once it reaches its maximum size ("high-water mark") it prunes itself (to its "low-water mark"). The cache high- and low-water-marks are measured in terms of "units", and each cached item by default uses one unit. All of the cache constructors, except for the default constructor, require the maximum number of units to be passed in. To change the number of units that each cache entry uses, either set the Units property of the cache entry, or extend the ICache implementation so that the inner LocalCacheEntry class calculates its own unit size. To determine the current, high-water and low-water sizes of the cache, use the cache object's Units, HighUnits and LowUnits properties. The HighUnits and LowUnits properties can be changed, even after the cache is in use. To specify the LowUnits value as a percentage when constructing the cache, use the extended constructor taking the percentage-prune-level.

Each cached entry never expires by default. To alter this behavior, use a constructor that takes the expiry-millis; for example, an expiry-millis value of 10000 will expire entries after 10 seconds. The ExpiryDelay property can also be set once the cache is in use, but it will not affect the expiry of previously cached items.

The cache can optionally be flushed on a periodic basis by setting the FlushDelay property or scheduling a specific flush time by setting the FlushTime property.

Cache hit statistics can be obtained from the CacheHits, CacheMisses and HitProbability read-only properties. The statistics can be reset by invoking ResetHitStatistics. The statistics are automatically reset when the cache is cleared (the Clear method).

The LocalCache implements the IObservableCache interface, meaning it provides event notifications to any interested listener for each insert, update and delete, including those that occur when the cache is pruned or entries are automatically expired.

This implementation is designed to support extension through inheritence. To override the one-unit-per-entry default behavior, extend the inner Entry class and override the CalculateUnits(Object) method.

See Also