Class: Cache

Cache(evictPolicyopt, capacityopt, eqCompareropt)

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.default.
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.
Author:
Source:

Members

capacity :Number

Returns the current capacity of this cache.
Type:
  • Number
Source:

capacity :void

Type:
  • void
Source:

evictionPolicy :EvictionPolicy|Number

Get the current @see {EvictionPolicy}.
Type:
Source:

evictionPolicy :void

Set the current @see {EvictionPolicy}.
Type:
  • void
Source:

isFull :Boolean

Returns true, if the cache's capacity is all used up.
Type:
  • Boolean
Source:

Methods

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: