How to Cache data?
Twitter/Facebook – last posts/tweets,
Background process -> local storage/database
Strategies:
- load fresh data, and when it fails take it from cache
always load data from local storage/db
Need of fresh data (seconds/minutes) – loading process can be to heavy,
How to communicate age of the data to the user?
Updates sent when online
Calling extrenal services – proxy pattern
Calling external service that uses time of the request internally
We don’t always want to download the whole internet (fb/twitter)
Better for apps that are ment to be used online – not data based, based of fresh data
Need of local db
Full copy (user/account context) of the server db
Need of Data Sync
Using external services (example: setting up new google callendar integration)
Different DB (server, mobiles) – proper API, platform agnostic
Data Sync is hard, expensive, difficult
Suitable for apps when it makes sense to download all the data (crm system)
Initial sync
Paginated (we don’t want to kill out the device), retries
User sepcific data/access rights
Can also be paginated
Timestamps
When paginating – timestamp returned from the server can be used
Server returns:
New object that has shown up since that time
Objects that were deleted (or we don’t have access right any more)
Changed objects (whole object or specific attributes)
When event driven approach – only new objects -> events
Gathers data from last timestamp
Cannot store all the devices timestamps
Data driven approach: store Creation/Update/Delete datetimes
Event driven approach: event timestamp
Last sync timestamp
Creation/update/delete datetime – not optimal
Flags: IsNew, IsDirty, ToBeDeleted, separate table for deleted ids
…analogy to merge & rebase
Allowing clients/devices to decide?
Created & updated -> NEW - NEW
Created & deleted -> don’t sync or 2 requests - Not posted!
Updated & deleted -> delete or 2 requests - Delete
Local side:
If new object in relation is replaced by existing one (form server) there are left overs in a database.
They shoud be cleaned
Regular vs. document/text data
Options:
Local changes
Server changes
Custom changes
Auto merge (not really possible if we update whole object)
Allowing user to merge