I have read a lot about how to use LoadData and SaveData to make my apps work offline. This is a great feature!
I found that if data is saved to the device, and I am offline, the app loads up SUPER quick! Unfortunately, while online, it would still do the normal collections, and the app would load slowly.
I would love to have the app identify if there is data stored in cache, and if there is, load that instead of collecting the data from it's original data source.
There didn't seem to be an easy way to take advantage of this, that I could find doing a quick search, so I figured I would share the super easy solution I stumbled upon.
Using IfError, we can take advantage of the error that is generated by the LoadData function.
Example of what would be in OnStart:
If(Connection.Connected,
IfError(
LoadData(colCollection, "savCollection", false),
Collect(colCollection, DataSource);
SaveData(colCollection, "savCollection")
),
LoadData(colCollection, "savCollection", true)
When no data is found in local cache, collect from the data source (and save the data to cache). When data is found in cache, collect from the cache! This greatly speeds up AppOnstart.
Considerations: Only use this method for data that you don't expect to change often. If the data changes often, you may need to come up with a synchronization schedule or an ability for the user to manually refresh the cached data.
If anyone has a better solution, please share!!
User | Count |
---|---|
262 | |
110 | |
92 | |
54 | |
43 |