Caching: Best Practices
Below are some strategies to leverage the caching features offered by the driver.
Read-Only Access to Data with Periodic Updates
A common use for caching is to have an application always query the cached data and only update the cache at set intervals, such as once every day or every two hours. There are two ways in which this can be implemented:
- Auto Cache = false and Offline = false. All queries issued by the application explicitly reference the table_name#Cache table. When the cache needs to be updated, the application executes a "CACHE table_name ..." statement to bring the cached data up to date.
- Offline = true. Caching is transparent to the application. All queries are executed against the table as normal, so most application code does not need to be aware that caching is done. To update the cached data, simply create a separate connection with Offline set to false and execute a "CACHE table_name ..." statement.
Fast Reporting from the Cache
Another common use is to have the application work with live data but execute more expensive queries (like reporting) against the local cache.
Auto Cache is a good option for this scenario. Enable Auto Cache and have the application code work with the live data. This will ensure the cache is updated every time SELECT is executed. Reporting logic runs queries on the table_name#Cache tables for better performance (especially for larger data sets).