To enhance their performance, modern applications typically maintain a cache with a local copy of their data, which they update when there are changes. There may be scenarios to completely refresh the cache data on each change. But when working with large amounts of data, each full refresh imposes a performance penalty. Since the need to update is only for changed data, in many scenarios refreshing only the recent data is enough. This can be achieved by using a caching mode called incremental.
Incremental caching is a way to limit the refreshing of the local cache of a client to only the changed data of the server, based on a timestamp. For each table that incremental caching is desired for, a timestamp column should be added. Then every time in one of those tables a row is inserted or modified, its value on the timestamp field should be set or updated accordingly. If that column is provided and incremental caching is enabled, the rest is done automatically.
In C1ConnectionStringBuilder, incremental caching is provided through two properties:
Property | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IncrementalUpdate |
Toggles incremental caching. The default value is false (off/disabled). | ||||||||||||||||
IncrementalUpdateColumn |
Sets the name of the column to be used as timestamp. If not provided, a default name is assumed for each service, according to the following table:
|
The following example enables incremental caching for a data source of OData, by setting IncrementalUpdate property to true:
C# |
Copy Code |
---|---|
C1ODataConnectionStringBuilder builder = new C1ODataConnectionStringBuilder(); builder.IncrementalUpdate = true; |
Incremental caching typically applies in two scenarios:
To query changed records after performing modifying operations (Insert/Update/Delete) on a table, implicit cache can be used. When modifying a table in the data source, the corresponding table in local cache will be marked over tolerance time. In offline mode, tolerance time is still considered. If the table exists, but not in tolerance time, then an exception is thrown.