new Cache(evictPolicyopt, capacityopt, eqCompareropt)
Creates a new, empty Cache., using the specified @see {EvictionPolicy} and
an initial capacity.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
evictPolicy |
EvictionPolicy | number |
<optional> |
Optional. Specify the eviction policy that is applied, if the cache has no more space left. |
capacity |
number |
<optional> |
Optional. Specify the initial capacity of this cache. The capacity can be increased and decreased later. |
eqComparer |
EqualityComparer.<TVal> |
<optional> |
Optional. Defaults To EqualityComparer. |
- Deprecated:
- Use @see {CacheMapBased} instead. This class will be removed from Version v3.0. A Cache is similar to a @see {DictionaryMapBased}, and also allows to manually and automatically evict items stored in it. A Cache's capacity is constrained.
- Source:
Members
(static) _counter
Used to assign a running number to new cache items.
- Source:
_capacity :number
Type:
- number
- Source:
_dict :Object.<(String|Symbol), CacheItem.<T>>
Type:
- Object.<(String|Symbol), CacheItem.<T>>
- Source:
_evictPolicy :EvictionPolicy|number
Type:
- EvictionPolicy | number
- Source:
capacity
- Source:
capacity
- Source:
evictionPolicy
- Source:
evictionPolicy
- Source:
isFull
- Source:
Methods
(generator) _entries()
- Source:
(generator) _evictNext() → {IterableIterator.<CacheItem.<T>>}
Returns items in the order they will be evicted, according to the policy.
- Source:
Returns:
- Type
- IterableIterator.<CacheItem.<T>>
_validateCapacity(capacity)
Parameters:
Name | Type | Description |
---|---|---|
capacity |
number | The capacity to check. Must be a positive integer. |
- Source:
Throws:
-
If the given capacity is not an integer or less than zero.
- Type
- Error
_validateEvictionPolicy(policy)
Parameters:
Name | Type | Description |
---|---|---|
policy |
EvictionPolicy | number | An @see {EvictionPolicy} |
- Source:
Throws:
-
If the given policy is not one of @see {EvictionPolicy}.
- Type
- Error
evict() → {T}
- Source:
Returns:
the evicted item.
- Type
- T
evictMany(count) → {Array.<T>}
Parameters:
Name | Type | Description |
---|---|---|
count |
Number |
- Source:
Returns:
The evicted items in an array.
- Type
- Array.<T>
get()
- Source:
peekEvict(amount) → {Array.<Object.<(String|Symbol), T>>}
Allows to peek at the next n items that will be evited next, without removing
them. Returns the items with as key/value pair.
Parameters:
Name | Type | Description |
---|---|---|
amount |
Number |
- Source:
Returns:
- Type
- Array.<Object.<(String|Symbol), T>>
remove()
- Source:
set(expireAfterMsecsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expireAfterMsecs |
Number |
<optional> |
Optional. if given a positive integer, then it will be used as the amount of milliseconds this entry will expire and remove itself from the cache. |
- Source:
Throws:
-
If this cache is full and no automatic eviction policy was set.
- Type
- Error
(generator) values()
- Source: