Class: MemoryCache

MemoryCache(capacity, lowWater)

Provides a limited-size memory cache of key-value pairs. The meaning of size depends on usage. Some instances of this class work in bytes while others work in counts. See the documentation for the specific use to determine the size units.

Constructor

new MemoryCache(capacity, lowWater)

Constructs a memory cache of a specified size.
Parameters:
Name Type Description
capacity Number The cache's capacity.
lowWater Number The size to clear the cache to when its capacity is exceeded.
Source:
Throws:
If either the capacity is 0 or negative or the low-water value is greater than or equal to the capacity or less than 1.
Type
ArgumentError

Members

capacity :Number

The maximum this cache may hold. When the capacity is explicitly set via this property, and the current low-water value is greater than the specified capacity, the low-water value is adjusted to be 85% of the specified capacity. The specified capacity may not be less than or equal to 0.
Type:
  • Number
Source:

(readonly) freeCapacity :Number

The size currently unused by this cache.
Type:
  • Number
Source:

lowWater :Number

The size to clear this cache to when its capacity is exceeded. It must be less than the current capacity and not negative.
Type:
  • Number
Source:

(readonly) usedCapacity :Number

The size currently used by this cache.
Type:
  • Number
Source:

Methods

addCacheListener(listener)

Adds a cache listener to this cache.
Parameters:
Name Type Description
listener MemoryCacheListener The listener to add.
Source:
Throws:
If the specified listener is null or undefined or does not implement both the entryRemoved and removalError functions.
Type
ArgumentError

clear(callListeners)

Removes all resources from this cache.
Parameters:
Name Type Description
callListeners Boolean If true, the current cache listeners are called for each entry removed. If false, the cache listeners are not called.
Source:

containsKey(key) → {Boolean}

Indicates whether a specified entry is in this cache.
Parameters:
Name Type Description
key String The key of the entry to search for.
Source:
Returns:
true if the entry exists, otherwise false.
Type
Boolean

entryForKey(key) → {Object}

Returns the entry for a specified key.
Parameters:
Name Type Description
key String The key of the entry to return.
Source:
Returns:
The entry associated with the specified key, or null if the key is not in the cache or is null or undefined.
Type
Object

putEntry(key, entry, size)

Adds a specified entry to this cache.
Parameters:
Name Type Description
key String The entry's key.
entry Object The entry.
size Number The entry's size.
Source:
Throws:
If the specified key or entry is null or undefined or the specified size is less than 1.
Type
ArgumentError

removeCacheListener(listener)

Removes a cache listener from this cache.
Parameters:
Name Type Description
listener MemoryCacheListener The listener to remove.
Source:
Throws:
If the specified listener is null or undefined.
Type
ArgumentError

removeEntry(key)

Remove an entry from this cache.
Parameters:
Name Type Description
key String The key of the entry to remove. If null or undefined, this cache is not modified.
Source:

setEntryAgingFactor(key, agingFactor)

Sets an entry's aging factor (multiplier) used to sort the entries for eviction. A value of one is normal aging; a value of two invokes 2x aging, causing the entry to become twice as old as a normal sibling with the same 'last used' timestamp. Setting a value of zero would be a "fountain of youth" for an entry as it wouldn't age and thus would sort to the bottom of the eviction queue.
Parameters:
Name Type Description
key String The key of the entry to modify. If null or undefined, the cache entry is not modified.
agingFactor Number A multiplier applied to the age of the entry when sorting candidates for eviction.
Source: