- Home /
Cache WWWForm or WWW request when offline
Is there an easy way to cache WWWForm or WWW request when there is no connection, and send it when user gets connected to the internet? I send statistics to my server about last gameplay for analytics and I am trying to improve it.
Answer by Dave-Carlile · Jun 22, 2015 at 07:40 PM
You can make this fairly simple by kind of reversing how you think about it. When you have some statistics, rather than sending them to the server, just add them to a persistent queue. You'll need to write code in order to keep the queue saved to disk, and load it when the app starts, etc. You have to make sure the persisting of your queue is solid.
Create a Coroutine that starts up when the game starts up. Its only job is to periodically see if there's something in the queue. If it finds something, try to submit it to the server. If that fails, it just leaves the item in the queue. The next time it tries to send something it'll see the same one, effectively retrying it.
Once that succeeds it gets removed from the queue. Repeat.
So the code that gathers that stats doesn't know or care about where they go or when - it just submits to a queue. A separate piece of your app has the sole responsibility of taking items from the queue and uploading them to the server. It will keep trying until it succeeds.
Your answer
Follow this Question
Related Questions
Does WWW has cache? Any official member can give us a result? 0 Answers
How to disable WWW caching in iOS? 1 Answer
How do I send data over the internet? 0 Answers
Disable Cache for WWW 7 Answers
Addressable Assets Cache 0 Answers