DataCache object
Introduction
The DataCache object is an extension of the DataSet object used by Solo_Predictor as a time-based storage device. It allows retaining rows in a DataSet object for a given period of time or up to a given maximum number of rows. When new data is added to a DataCache, each row in the matrix is assigned a time stamp (if none was passed as the axisscale of a DataSet object) and data which has "expired" or old data that exceeds the maximum number of allowable rows is removed.
DataCache objects can hold an unlimited number of "blocks", each with its own retention policy.
DataCache Properties
Retention Policy Properties
.block | Sets or retrieves the block being used by the DataCache object. Each block can have its own retention policy and each has its own underlying DataSet object. Default = 1. |
.maxcount | Sets or retrieves the maximum number of rows allowable by the retention policy. When an .add method would push the DataCache object over this number of rows, old rows are removed to keep the total at this limit. Default = 1000. |
.maxage | Sets or retrieves the maximum age (in hours) allowable by the retention policy. Data which is older than this are automatically removed from the DataCache. Default = 24. |
Read-Only Properties
.data | Retrieves the current DataSet object for the current block. |
.first | Retrieves the text-formatted date associated with the oldest (first) item in the DataCache object. |
.last | Retrieves the text-formatted date associated with the newest (last) item in the DataCache object. |
DataCache Methods
.add(newdata) | Appends newdata as new samples (rows) to the data. See "Adding Data" below. |
.empty | Removes all data from the current block regardless of retention policy. |
Adding Data
When new data is added to an existing DataCache block, several tests are performed:
- The first samples axisscale set of the new data is checked for timestamps. If there is no axisscale{1} or it does not appear to contain valid timestamps, then all the rows in the new data are assigned a timestamp of the time at which the data was added. Any existing axisscale (that isn't a time stamp already) will be overwritten.
- The number of variables (columns) in newdata are tested against the number of columns in the current data block. If they do not match, the current data block is overwritten with the new data.
- Datacache objects are persistent and global meaning that the stored data will persist when Solo_Predictor is restarted and that any users accessing the same copy of Solo_Predictor will have access to the same datacache objects. Thus, data can be shared among users but care must be taken to avoid multiple users attempting to add data to the same datacache block (each block is handled separately, so an easy solution is to use separate blocks for each user.)
Example
The following Solo_Predictor script opens the DataCache block #2, sets its maximum age to 48 hours, then adds mynewdata to the object:
obj = @datacache; obj.block = '[2]'; obj.maxage = '[48]'; obj.add(mynewdata);
The same thing as a Matlab-formatting call:
obj = datacache('block',2) %get DataCache block 2 obj.maxage = 48; %set maxage to 48 hours obj.add(mynewdata); %add "mynewdata" to current block