User Guide > TDV Caching > Defining Cache Refresh Behavior > Controlling Cache Refresh Behavior for Multiple Resources
 
Controlling Cache Refresh Behavior for Multiple Resources
Cache policies can be defined to control the cache refresh behavior for several TDV resources. Defining cache policies allows you to reuse cache refresh definitions for multiple TDV resources. The logic inherent to the cache policy behavior manages cache refresh behavior for dependent resources and ensures better data integrity when updated caches for resources that have data dependencies. Keeping data in your cache up-to-date ensures that results are correct. When a view, table, or procedure 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.
Multi-Table Cache Refresh Limitations
If you have muti-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.
If you schedule a reintrospection of the cache data source at exactly the same time as cache refresh, it might lead to errors. The multi-table cache refresh drops and recreates the indexes during cache refresh so it can appear that indexes are missing.
To control cache refresh behavior
1. You must follow the instructions in Defining a Cache Policy.
2. For each resource that you want to have associated with the policy, follow the instructions in one of the following sections:
Assigning Resources to a Cache Policy
Assigning a Cache Policy to a Resource
Defining a Cache Policy
Cache policies define cache refresh and clearing behavior. The cache policies can then be applied to resources that are being cached.
Cache Policy Limitations
Cache policies are not supported for:
Procedures with input parameters.
Pull-based incremental caches when defined on a table or view.
Push-based incremental caches when defined on a table or view.
To create a cache policy
1. From the Studio resource tree, expand <host>/policy/cache.
2. Right-click and select New Cache Policy.
3. Name the policy.
4. Click OK.
5. Open the new cache policy.
6. Select the Cache Policy Settings tab. For information about the Resources tab, see Assigning Resources to a Cache Policy.
7. Select the Enable check box to enable this cache policy. If you decide to leave it cleared, you can continue to define the policy, but it will not be active until you select the Enable check box.
8. Accept the default or specify the data source where you want data about the cache policy to be stored. You can use the Browse button to browse through the Studio resource tree of available data sources.
9. 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.
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.
10. 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.
11. Optionally, you can define pre-and post-refresh actions. As described in Defining Pre- and Post-Actions for a Full Refresh Mode Cache.
12. 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.
13. Save the cache settings.
Assigning Resources to a Cache Policy
You can assign one or more resources to a cache policy to have their cache refreshes managed by the same refresh definition. After a resource is assigned to a cache policy and the cache policy is saved, TDV sets the definitions on Caching tab of that resource to those defined by the cache policy. If caching was not enabled for the resource that you assign to the cache policy, it is enabled and the majority of the fields on the Caching tab are dimmed to indicate that they are under the control of the cache policy.
To associate a resource with a cache policy
1. Make sure that cache policies have been defined following the instructions in Defining a Cache Policy.
2. In Studio, open a cache policy.
3. Select the Resources tab.
4. Add resources to the list to be managed by this cache refresh policy in one of the following ways:
Select one or more resources from the Studio resource tree and drag them into the Resources text field.
Click the green plus button and use the Select Resources dialog to navigate to the resource you want to add.
5. Save your cache policy.
Studio does validation of the policy definitions for the resources in the list and issues messages if there are things you need to fix.
6. Fix resource definitions if prompted by any Studio messages.
7. Save your changes.
Assigning a Cache Policy to a Resource
Defining cache policies allows you to reuse cache refresh definitions for multiple TDV resources. The logic inherent to the cache policy behavior manages cache refresh behavior for dependent resources and ensures better data integrity when updated caches for resources that have data dependencies. If you did not add the resource to the cache policy on the Resources tab, you can follow these steps to associate a specific resource to a cache policy.
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.
Cache Policy Limitations
Cache policies are not supported for:
Procedures with input parameters.
Pull-based incremental caches when defined on a table or view.
Push-based incremental caches when defined on a table or view.
To associate a resource with a cache policy
1. Make sure that cache policies have been defined following the instructions in Defining a Cache Policy.
2. In Studio, open a view, table, or procedure that has had caching enabled.
3. Select the Caching tab.
4. Locate the Cache Policy field.
5. Select the cache policy that you want to be used to control cache refresh and clearing behavior for this resource. You can use the Open Policy button to open the policy and review or change its settings as necessary.
6. (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.)
7. Save your resource.
Note: The Refresh Now button appears enabled for each resource that is not associated with a cache policy. If the resource is associated with a cache policy, however, the button will appear disabled.