cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dnourie
Advocate IV
Advocate IV

How to use LoadData and IfError to maximize offline use and speed up the app OnStart

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!!

0 REPLIES 0

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,594)