Data Layer
The app has an extra layer underneath the stores that handle actual storage of the data. There are two versions of this data layer: the cache data and the state data.
Cache Data
The cache data layer provides for temporary caching of data. Data stored here can be removed by the system, either due to a time limit or a memory limit (only time limit is currently supported).
When data is placed in the cache, it gets a time to live. Whenever data is accessed, its age is reset. On a regular basis, all cache data that has expired (has not been updated or retrieved recently) will be removed from the cache.
State Data
The state data layer stores data that identifies the application state (where in the application am I, what am I doing). The data layer is implemented using local data storage on the device. The state data layer also maintains an internal copy to be able to provide direct access to the data (accessing local storage is an asynchronous operation).
The state data is loaded from local storage when the app starts up. Any updates to the state data are updated in memory, and then an asynchronous update to the local storage version is initiated.
State data is versioned. When the state data is loaded, the version number of the retrieved data is compared with the current version number. If they are different, code can be included to do a conversion from the old to the new data. At the end of the initialization process, the local storage data has been updated to the current version of the application.
