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. |
Returns:
A new data cache instance.
- Type
- DataCache
Methods
-
cancelCount()
-
Aborts the count operation (used within promise callback)
-
cancelFilter()
-
Aborts the filter operation (used within promise callback)
-
cancelReadPage()
-
Aborts the readPage operation. (used within promise callback)
-
cancelReadPage()
-
Aborts the savePage operation. (used within promise callback)
-
cancelReadRange()
-
Aborts the readRange operation (used within promise callback)
-
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.
Returns:
A promise that has no value and can't be canceled.- Type
- Object
-
count() → {Object}
-
Counts the number of items in the collection.
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 indexNumber The index of the item to start filtering backward from. countNumber Maximum number of items to include in the result. predicatefunction Callback function returning a boolean that determines whether an item should be included in the result or not. 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 indexNumber The index of the item to start filtering forward from. countNumber Maximum number of items to include in the result. predicatefunction Callback function returning a boolean that determines whether an item should be included in the result or not. 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 indexNumber Zero-based index of record range to read. countNumber Number of records in the range. 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.
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 messageString Message text. 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 operationDataCacheOperation Operation being run. opTargetStateObject Operation state to transition to. cacheStateObject Current cache state. dataObject <optional>
This state machine contains behavior common to read and prefetch operations. -
<inner> changeState(newState)
-
Updates the cache's state and signals all pending operations of the change.
Parameters:
Name Type Description newStateObject New cache state. This method is a no-op if the cache's current state and the new state are the same. -
<inner> clearStore() → {DjsDeferred}
-
Removes all the data stored in the cache.
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 operationDataCacheOperation Operation to dequeue. This method is used as a handler for the operation's oncomplete event. -
<inner> destroyStateMachine(operation, opTargetState, cacheState)
-
State machine describing the behavior of a clear operation.
Parameters:
Name Type Description operationDataCacheOperation Operation being run. opTargetStateObject Operation state to transition to. cacheStateObject 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. -
<inner> fetchPage(start) → {DjsDeferred}
-
Requests data from the cache source.
Parameters:
Name Type Description startNumber Zero-based index of items to request. 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 indexNumber The index of the item to start filtering from. countNumber Maximum number of items to include in the result. predicatefunction Callback function returning a boolean that determines whether an item should be included in the result or not. backwardsBoolean 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. Returns:
A promise for an array of results.- Type
- DjsDeferred
-
<inner> fireOnIdle()
-
Fires an onidle event if any functions are assigned.
-
<inner> prefetch(start)
-
Creates and starts a new prefetch operation.
Parameters:
Name Type Description startNumber 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). -
<inner> prefetchStateMachine(operation, opTargetState, cacheState, data)
-
State machine describing the behavior of a prefetch operation.
Parameters:
Name Type Argument Description operationDataCacheOperation Operation being run. opTargetStateObject Operation state to transition to. cacheStateObject Current cache state. dataObject <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. -
<inner> readPage(key) → {DjsDeferred}
-
Requests a page from the cache local store.
Parameters:
Name Type Description keyNumber Zero-based index of the reuqested page. 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 operationDataCacheOperation Operation being run. opTargetStateObject Operation state to transition to. cacheStateObject Current cache state. dataObject <optional>
- isPrefetchBoolean Flag indicating whether a read (false) or prefetch (true) operation is running. This state machine contains behavior common to read and prefetch operations. -
<inner> readStateMachine(operation, opTargetState, cacheState, data)
-
State machine describing the behavior of a read operation.
Parameters:
Name Type Argument Description operationDataCacheOperation Operation being run. opTargetStateObject Operation state to transition to. cacheStateObject Current cache state. dataObject <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. -
<inner> savePage(key, page) → {DjsDeferred}
-
Saves a page to the cache local store.
Parameters:
Name Type Description keyNumber Zero-based index of the requested page. pageObject Object with (i)ndex, (c)ount, (d)ata, and (t)icks. 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 successfunction Success callback. errorfunction Errror callback. -
<inner> storeFailureCallback(deferred) → {function}
-
Creates a function that handles a store error.
Parameters:
Name Type Description deferredDjsDeferred Deferred object to resolve. 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 pageObject Object with (i)ndex, (c)ount, (d)ata. pageBytesNumber Size of the page in bytes.