User Guide > TDV Caching > Defining Cache Refresh Behavior > Controlling Cache Refresh Behavior for Individual Resources
 
Controlling Cache Refresh Behavior for Individual Resources
Caches can be refreshed immediately or periodically using Studio. Cache policies can be defined to control the cache refresh behavior for several TDV resources. Caches can also be refreshed programmatically. Keeping data in your cache up-to-date ensures that results are correct. When a view or table resource is refreshed, the entire result set is obtained for the object and written to the cache.
Modifying the query of the view (or table) that you have caching defined on does not automatically update the cache. You must execute a refresh or wait for the next scheduled refresh cycle to get the correct result set.
Refreshing and Clearing the Cache for One Resource Using Studio
Refreshing and Clearing Your Cache Programmatically
Refreshing and Clearing the Cache for One Resource Using Studio
You can use Studio to refresh your cache data immediately, or you can use Studio to configure regularly scheduled refreshes of your cache data.
For views and tables, the expiration period applies to the whole result set. For procedures, each input variants data has its expiration tracked separately.
Note: If you have multi-table caching defined, TDV first attempts to clear the cache using a TRUNCATE command. If the TRUNCATE command is not supported, a DELETE command is attempted.
To define cache refresh and expiration schedules
1. In Studio, open a view or procedure that has had caching enabled.
2. Select the Caching tab.
3. Under Refresh Mode, specify the cache refresh mode. Refreshing a cached resource retrieves data from the sources and clears stale data as specified.
You can refresh the cache immediately by clicking Refresh Now.
 
Option
Description
Manual
The resource owner or an administrator must manually refresh the cache using Refresh Now or programmatically by invoking the RefreshResourceCache procedure. See the TDV Application Programming Interfaces Guide.
Any user with the ACCESS TOOLS right who is given appropriate privileges can also refresh the cache manually.
If your cache is controlled by a cache policy, using a periodic or programmatic refresh is suggested.
Exactly Once
To refresh the cache just once at a specific time, select, and specify the time to start caching in the set of drop-down boxes in the section labeled Start on. The Hour field accepts a typed entry of 0—and when you save the resource, Studio automatically converts the hour to 12 and AM/PM to AM.
Periodic
To refresh the cache periodically, select Periodic and specify in the Refresh every section how often to execute the resource for caching: every x number of seconds, minutes, hours, days, weeks, months, or years. In the Start on fields, specify the time and date to begin periodic refresh mode.
4. Under Expiration Schedule, select Never expire, or select Expire after and specify the time period. The expiration period applies from the end of a refresh. The Expire after option is disabled if you are using incremental caching.
5. Under Advanced there are a variety of combinations:
a. If you select Full Refresh Mode, you can define pre-and post-cache actions, as described in Defining Pre- and Post-Actions for a Full Refresh Mode Cache.
b. If you select Incremental Refresh Mode, you can define pre-and post-cache actions, as described in Setting Up Pull-Based Incremental Cache.
6. Specify when to clear the cache.
 
Cache Clears Option
Description
when user clears it manually
Clear the cache only when the Clear Now button, an API call, or on cache expiration (Expire after has been selected in the Expiration Schedule section).
when refresh fails
(For full refresh caching only) Selecting this option would clear the cache if a refresh fails. This option allows access to previously cached data during a refresh.
when refresh begins
(For full refresh caching only) Selecting this option would automatically clear the cache before starting a refresh. Any clients attempting to read from the cached data must wait for the new data.
When load fails
(For push-based incremental caching only) Selecting this option would automatically clear the cache if the loading of data did not complete.
When initial load begins
(For push-based incremental caching only) Selecting this option would automatically clear the cache before starting a refresh. Any clients attempting to read from the cached data must wait for the new data.
7. (For procedures only) Define the maximum number of variants you want stored in the cache from the results of the procedure you are caching. Maximum number of unique set of input parameter values. (Default is 32.)
8. Save the cache settings.
Refreshing and Clearing Your Cache Programmatically
If you have chosen to programmatically refresh your cached data, you have the following options:
TDV provides stored procedures that can be used to clear cache contents, initiate a refresh, and change the state of a cache. You can use a SQL Script to call and perform any caching functions.
Using the TDV trigger function, it is possible to respond to system- or user-generated events that call a procedure to refresh a cache.
Administrative Web services can be used to define external programs that clear, refresh, enable, and disable the cache.
The following TDV API calls are available for use from SQL Scripts or Java Procedures, or that can be published for use from clients. Each of the following is accessed in Studio under <localhost>/lib/resource:
ClearResourceCache(path, type)
CreateResourceCacheKey(path, type, cacheKey)
LoadResourceCacheStatus(path, type)
RefreshResourceCache(path,type)
UpdateResourceCacheEnabled(path, type, enabled)
UpdateResourceCacheKeyStatus(path, type, cacheKey, status, startTime, message)
For details, see the TDV Application Programming Interfaces Guide.
The following Web services are available for use from clients outside the server. They can be accessed in Studio under Data Services/Web Services/system/admin/resource/operations:
clearResourceCache (path, type)
getResourceCacheConfig(path, type)
refreshResourceCache (path, type)
updateResourceCacheConfig (path, type, detail, cacheConfig)