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: