Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching Data for iOS/Android mobile Apps to work with Pagination

Give the following scenario. I have a mobile App on iOS/Android which is connected to a server backend via REST. Within the app you can display news items. These items can be created, edited and deleted of you are the creator of the item. On one page in the app there is a news feed where you can see an overview of news items created by other app users. The iOS/Android app stores the data of these news items in a local sqlite database. When the user scrolls down the list of items further items should be loaded if there are any.

The task I want to solve is how the items will be cached in the SQLite database to work with pagination. The cache must be updated sometimes when items are deleted or reordered on the server. This must be taken into account when working with pagination.

Here is the algorithm I've used so far:

  1. if the feed page opens check if there are any items to display in the sqlite database

    • if true retrieve p items with offset offset=0 from the database and contact the server to check if the first p items should be updated or deleted
      • if items should be updated or deleted perform these operations on the items in display
    • else contact the server for p items with offset offset=0 and display them
  2. if the user scrolls down start 1. again with offset = offset + p

How does caching data for mobile apps work with pagination?

like image 786
confile Avatar asked Jan 18 '15 14:01

confile


1 Answers

The question is how long you want to store data. You can store every data you get in part:

"else contact the server for p items with offset offset=0 and display them"

And set some time stamp to data. When time stamp expires you delete data ( in background ). In this way you save a lot of requests and also you don't waste with memory.

Hope this helps you with your problem.

like image 94
Vojta Avatar answered Nov 07 '22 11:11

Vojta