Class: DataCache

DataCache

new DataCache(options) → {DataCache}

Creates a data cache for a collection that is efficiently loaded on-demand.
Parameters:
Name Type Description
options Options for the data cache, including name, source, pageSize, prefetchSize, cacheSize, storage mechanism, and initial prefetch and local-data handler.
Source:
Returns:
A new data cache instance.
Type
DataCache

Methods

cancelCount()

Aborts the count operation (used within promise callback)
Source:

cancelFilter()

Aborts the filter operation (used within promise callback)
Source:

cancelReadPage()

Aborts the readPage operation. (used within promise callback)
Source:

cancelReadPage()

Aborts the savePage operation. (used within promise callback)
Source:

cancelReadRange()

Aborts the readRange operation (used within promise callback)
Source:

clear() → {Object}

Cancels all running operations and clears all local data associated with this cache. New read requests made while a clear operation is in progress will not be canceled. Instead they will be queued for execution once the operation is completed.
Source:
Returns:
A promise that has no value and can't be canceled.
Type
Object

count() → {Object}

Counts the number of items in the collection.
Source:
Returns:
A promise with the number of items.
Type
Object

filterBack(index, count, predicate) → {DjsDeferred}

Filters the cache data based a predicate. Specifying a negative count value will yield all the items in the cache that satisfy the predicate.
Parameters:
Name Type Description
index Number The index of the item to start filtering backward from.
count Number Maximum number of items to include in the result.
predicate function Callback function returning a boolean that determines whether an item should be included in the result or not.
Source:
Returns:
A promise for an array of results.
Type
DjsDeferred

filterForward(index, count, predicate) → {DjsDeferred}

Filters the cache data based a predicate. Specifying a negative count value will yield all the items in the cache that satisfy the predicate.
Parameters:
Name Type Description
index Number The index of the item to start filtering forward from.
count Number Maximum number of items to include in the result.
predicate function Callback function returning a boolean that determines whether an item should be included in the result or not.
Source:
Returns:
A promise for an array of results.
Type
DjsDeferred

readRange(index, count) → {DjsDeferred}

Reads a range of adjacent records. New read requests made while a clear operation is in progress will not be canceled. Instead they will be queued for execution once the operation is completed.
Parameters:
Name Type Description
index Number Zero-based index of record range to read.
count Number Number of records in the range.
Source:
Returns:
A promise for an array of records; less records may be returned if the end of the collection is found.
Type
DjsDeferred

toObservable()

Creates an Observable object that enumerates all the cache contents.
Source:
Returns:
A new Observable object that enumerates all the cache contents.

<inner> cacheFailureCallback(message) → {function}

Creates a function that handles a callback by setting the cache into failure mode.
Parameters:
Name Type Description
message String Message text.
Source:
Returns:
Function to use as error callback. This function will specifically handle problems with critical store resources during cache initialization.
Type
function

<inner> cancelStateMachine(operation, opTargetState, cacheState, data)

State machine describing the behavior for cancelling a read or prefetch operation.
Parameters:
Name Type Argument Description
operation DataCacheOperation Operation being run.
opTargetState Object Operation state to transition to.
cacheState Object Current cache state.
data Object <optional>
This state machine contains behavior common to read and prefetch operations.
Source:

<inner> changeState(newState)

Updates the cache's state and signals all pending operations of the change.
Parameters:
Name Type Description
newState Object New cache state. This method is a no-op if the cache's current state and the new state are the same.
Source:

<inner> clearStore() → {DjsDeferred}

Removes all the data stored in the cache.
Source:
Returns:
A promise with no value.
Type
DjsDeferred

<inner> dequeueOperation(operation)

Removes an operation from the caches queues and changes the cache state to idle.
Parameters:
Name Type Description
operation DataCacheOperation Operation to dequeue. This method is used as a handler for the operation's oncomplete event.
Source:

<inner> destroyStateMachine(operation, opTargetState, cacheState)

State machine describing the behavior of a clear operation.
Parameters:
Name Type Description
operation DataCacheOperation Operation being run.
opTargetState Object Operation state to transition to.
cacheState Object Current cache state. Clear operations have the highest priority and can't be interrupted by other operations; however, they will preempt any other operation currently executing.
Source:

<inner> fetchPage(start) → {DjsDeferred}

Requests data from the cache source.
Parameters:
Name Type Description
start Number Zero-based index of items to request.
Source:
Returns:
A promise for a page object with (i)ndex, (c)ount, (d)ata.
Type
DjsDeferred

<inner> filter(index, count, predicate, backwards) → {DjsDeferred}

Filters the cache data based a predicate.
Parameters:
Name Type Description
index Number The index of the item to start filtering from.
count Number Maximum number of items to include in the result.
predicate function Callback function returning a boolean that determines whether an item should be included in the result or not.
backwards Boolean True if the filtering should move backward from the specified index, falsey otherwise. Specifying a negative count value will yield all the items in the cache that satisfy the predicate.
Source:
Returns:
A promise for an array of results.
Type
DjsDeferred

<inner> fireOnIdle()

Fires an onidle event if any functions are assigned.
Source:

<inner> prefetch(start)

Creates and starts a new prefetch operation.
Parameters:
Name Type Description
start Number Zero-based index of the items to prefetch. This method is a no-op if any of the following conditions is true: 1.- prefetchSize is 0 2.- All data has been read and stored locally in the cache. 3.- There is already an all data prefetch operation queued. 4.- The cache has run out of available space (overflowed).
Source:

<inner> prefetchStateMachine(operation, opTargetState, cacheState, data)

State machine describing the behavior of a prefetch operation.
Parameters:
Name Type Argument Description
operation DataCacheOperation Operation being run.
opTargetState Object Operation state to transition to.
cacheState Object Current cache state.
data Object <optional>
Prefetch operations have the lowest priority and will be interrupted by operations of other kinds. A preempted prefetch operation will resume its execution only when the state of the cache returns to idle. If a clear operation starts executing then all the prefetch operations are canceled, even if they haven't started executing yet.
Source:

<inner> readPage(key) → {DjsDeferred}

Requests a page from the cache local store.
Parameters:
Name Type Description
key Number Zero-based index of the reuqested page.
Source:
Returns:
A promise for a found flag and page object with (i)ndex, (c)ount, (d)ata, and (t)icks.
Type
DjsDeferred

<inner> readSaveStateMachine(operation, opTargetState, cacheState, data, isPrefetch)

State machine describing the behavior for reading and saving data into the cache.
Parameters:
Name Type Argument Description
operation DataCacheOperation Operation being run.
opTargetState Object Operation state to transition to.
cacheState Object Current cache state.
data Object <optional>
-
isPrefetch Boolean Flag indicating whether a read (false) or prefetch (true) operation is running. This state machine contains behavior common to read and prefetch operations.
Source:

<inner> readStateMachine(operation, opTargetState, cacheState, data)

State machine describing the behavior of a read operation.
Parameters:
Name Type Argument Description
operation DataCacheOperation Operation being run.
opTargetState Object Operation state to transition to.
cacheState Object Current cache state.
data Object <optional>
Read operations have a higher priority than prefetch operations, but lower than clear operations. They will preempt any prefetch operation currently running but will be interrupted by a clear operation. If a clear operation starts executing then all the currently running read operations are canceled. Read operations that haven't started yet will wait in the start state until the destory operation finishes.
Source:

<inner> savePage(key, page) → {DjsDeferred}

Saves a page to the cache local store.
Parameters:
Name Type Description
key Number Zero-based index of the requested page.
page Object Object with (i)ndex, (c)ount, (d)ata, and (t)icks.
Source:
Returns:
A promise with no value.
Type
DjsDeferred

<inner> saveSettings(success, error)

Saves the cache's current settings to the local store.
Parameters:
Name Type Description
success function Success callback.
error function Errror callback.
Source:

<inner> storeFailureCallback(deferred) → {function}

Creates a function that handles a store error.
Parameters:
Name Type Description
deferred DjsDeferred Deferred object to resolve.
Source:
Returns:
Function to use as error callback. This function will specifically handle problems when interacting with the store.
Type
function

<inner> updateSettings(page, pageBytes)

Updates the cache's settings based on a page object.
Parameters:
Name Type Description
page Object Object with (i)ndex, (c)ount, (d)ata.
pageBytes Number Size of the page in bytes.
Source: