Caching is used to speed up loading of requested data to a user's mobile device. Cache is a copy of data obtained from data source resource saved on a mobile platform server. When data is requested from a mobile device the server returns update from the saved cache without addressing to data source. This reduces time for request processing.
TIP. If the amount of requested data is small, use transfer of transaction data to process response on lost connection.
Cache stores data source responses with specifying versions, cache saving date, cache validity expiration time, information for comparing request with cache: target resource, credentials used on data source request, and input request parameters. Resource cache is available to control caches by parameters in the Cache Control subsection.
Delta is a difference between two versions of resource data that enables a mobile device to restore new resource version from the stored old version.
Delta contains the following for each resource table:
Full list of inserted strings.
Identifiers of deleted strings.
Numbers of start and end cache data version. Resource cache data version corresponds to the number of data source request and is available on viewing cache in the Version string.
For details about delta use in requests, see the Designating Delta Versions in Requests section.
Apart from version number, resource cache contains the ETag unique identifier sent together with data or delta. If the unique identifier is specified in the request, a mobile platform server automatically determines cache version, to which request corresponds; it calculates and sends delta to a mobile device between the request and the latest cache version on the server.
Interaction between a mobile device, a mobile platform server, and a data source on caching:
Mobile device:
Stores one version of cache by parameters.
Generates data get requests to platform server.
Refreshes stored cache on getting delta from a mobile platform server.
Mobile platform server:
Stores several versions of cache by parameters for each resource link, credentials, and set of input parameter values.
Receives requests from mobile device.
Checks if the current cache version for requested data is actual.
Updates data via request to data source and calculates hash sum by resource record identifiers.
Calculated delta between actual cache version and version on a mobile device by cache version number.
Sends delta or full data version to a mobile device.
Data source:
Generates the response corresponding to request parameters, and sends it to a mobile platform server.
Data refresh algorithm on a mobile device:
A mobile device sends request to data refresh.
A mobile platform server checks if requested data cache is actual:
If cache is actual, the server calculates delta based on saved data without addressing the data source.
If cache is outdated, the server requests data from the data source and calculates delta.
Delta is sent to a mobile device from a mobile platform server.
A mobile device restores actual version based on the saved data and obtained delta.
Cache use scheme when working with one resource:
Data integrity check is executed for cached resources:
When data is obtained from a data source, the hash sum is calculated on a mobile platform server by requested resource record identifiers.
The hash sum calculated on a mobile platform server is sent to a mobile device together with the actual cache version or the delta between the last two cache versions.
Resource data is updated on the mobile device, after which the hash sum is calculated on the mobile device.
The hash sum obtained from a mobile platform server is compared with the hash sum calculated on a mobile device:
If hash sums match, the data integrity check is completed.
If hash sums do not match, data on a mobile device is deleted, and the repeated request of resource data from a mobile platform server is executed. After getting data on the mobile device, the resource data is updated, the hash sum is calculated similarly to Step 3, and hash sums are compared similarly to Step 4:
If hash sums match, the data integrity check is completed.
If hash sums do not match, an error message about mismatching hash sums is displayed on the mobile device.
To use caching, select the Cache checkbox that is available after resource import. If the checkbox is selected, additional caching parameters are displayed:
Cache Validity. Specify time as: <hours : minutes : seconds>, during which cache is considered actual after it is created. This parameter and cache creation date are used to calculate the time, after which cache is considered outdated. If data is requested from a mobile device until when cache is already considered outdated, the user gets data from the saved cache, otherwise a mobile platform server requests a data source. To avoid excessive use of memory, set a schedule to delete outdated caches. The box is mandatory.
Saved Strings. Specify the number of strings from 10000 to 100000 written to cache in one iteration.
NOTE. If the number of strings is not specified, speed of cache writing is maximum, although memory use is also maximum.
Stored Old Versions. Specify the number of stored cache versions that ensure processing of requests from mobile devices with different versions of saved data. The number of cache versions if unlimited by default.
NOTE. Stored old versions occupy memory on a mobile platform server.
Store last cache version in RAM. Select the checkbox to store last cache version in RAM and database. Using the last cache version from RAM speeds up primary data loading to a mobile device. The checkbox is deselected by default, and the last cache version is stored in database.
NOTE. When this parameter is used, take into account the following:
● cache size should not exceed 512 Mb.
● Storing last cache version results in the increased RAM usage.
Number of deltas in RAM. Specify the number of deltas that will store changes between older versions and the last actual cache version in RAM. Storing the previously calculated delta between the older version and the last actual cache version in RAM speeds up data loading to a mobile device and decreases CPU load.
NOTE. When this parameter is used, take into account the following:
● Number of deltas in RAM should be less or equal to the number of older cache versions specified in the Older Versions to Store parameter.
● Storing the specified number of deltas results in the increased RAM usage.
Change resource input parameters to get a data slice via requests, and click the Save button. The resource is added to the list of data source resources, and its input parameters are available to control resource cache.
Requests to data source resources are given in the Method for Working with Table Resources section.
See also: