Constructs a new, empty FetchedIntervalCache
. Entries will be sorted by the sortKey
provided.
This function requires an IntervalFactory
, while makeCache()
provides a default one that should be
sufficient in most cases.
Private
_intervalPrivate
_intervalsPrivate
_listenersPrivate
_sortPrivate
_entryPrivate
_findPrivate
_iterateIterates through the _FetchedInterval
s and the empty intervals between _FetchedInterval
s
in the cache from iterationInterval.from
to iterationInterval.to
.
Attempts to add the entry to the cache. createInterval
indicates if a new interval will be
created if an appropriate one does not already exist. Returns true if the entry is added, and
false otherwise (including if another entry with the same sort key value already exists).
Appropriate callback(s) are invoked if the entry is added.
"Subscribes" the callback function to the interval, such that the callback will be invoked whenever there are changes to the interval. Throws an error if the callback provided is already subscribed to an interval.
Returns the entries in the provided interval, as well as the intervals that are not in the cache (these should be subsequently fetched from the backend, so that the requested interval can be completely filled in).
Get the entry with a sort value greater than or equal to the value provided. Returns a
missingInterval
if an appropriate entry is not found in the cache, but could exist. Returns
the entry if it is found. Returns noValue
if all possible intervals have been fetched, and
no appropriate entry exists.
Get the entry with a sort value less than or equal to the value provided. Returns a
missingInterval
if an appropriate entry is not found in the cache, but could exist. Returns
the entry if it is found. Returns noValue
if all possible intervals have been fetched, and
no appropriate entry exists.
Adds a new interval of entries to the cache. Overlapping parts of existing intervals will be
overwritten. Throws an error if entries
are not sorted ascending by sort key, or if any of
the entries
have a duplicate sort value, or if any of the entries
have a sort value
outside of the insertInterval
. Appropriate callback(s) are invoked.
Minifies this cache, so that it is smaller for JSON.stringify()
or database insertion.
"Unsubscribes" the given callback function. Returns true if the given callback was "subscribed" to an inteval, and false otherwise.
Static
makeReturns a new, empty FetchedIntervalCache
, with entries sorted by the sortKey
provided.
Static
unminifyConstructs a FetchedIntervalCache from a minified value. entryUnminifier
should throw an
error if passed a malformed or invalid minified entry.
Generated using TypeDoc
A set of distinct (non-intersecting)
IntegerInterval
s, each containing sorted, unique data. Each interval corresponds to one or more queries to a backend database.