User Guide > TDV Caching > Defining Cache Refresh Behavior > Defining Pre- and Post-Actions for a Full Refresh Mode Cache
 
Defining Pre- and Post-Actions for a Full Refresh Mode Cache
When caching data, you might want to have actions take place before or after the cache data is refreshed. These pre- and post-actions are available for the automatic, single table, or multi-table caching modes.
For example, before the cache is refreshed you might want to send email notifications that the data is about to be refreshed. After the cache is refreshed, you might want to define or update the indexes associated with the data.
Within Studio, you can define procedures or scripts that have no input or output parameters to act as your pre- and post-actions. They can, however, call other procedures to execute subtasks within the pre-refresh or post-refresh operation.
The pre and post procedures can be a SQL script procedure or a custom Java procedure. They cannot be an XSLT transform or XQuery procedure.
To define a pre- or post-refresh actions
1. Create a new SQL script or Java procedure using the instructions in Java Procedures or Adding a Custom Java Procedure.
To use an existing SQL script or procedure locate the script or procedure within the Studio resource tree.
2. Make sure that the script or procedure does not have input or output parameters.
3. Evaluate the following TDV API calls for use in Studio under <localhost>/lib/util:
GetEnvironment—Can be used to return one or more of the system properties to your Pull-Based incremental caching SQL script
GetProperty—Can be used to return one or more of the system properties to your Pull-Based incremental caching custom Java procedure.
4. Review other functions under the lib directory to determine if they can help you achieve the action that you want for your pre- or post-action. Other functions of possible interest might include:
CreateResourceCacheKey is used to create a cache key for a given resource.
TestDataSourceConnection is used to test to see if a data source's connection is operational.
ClearResourceCache(path, type) is used to clear the cache on a resource.
UpdateResourceCacheKeyStatus(path, type, cacheKey, status, startTime, message) is used to update the cache key for the specified resource.
GetResourceCacheStatusProcedure is used with CreateResourceCacheKey and UpdateResourceCacheKeyStatus to support external cache loading. Returns Cache status information for a given cache key.
5. Save the script or procedure.
6. In Studio, open a view or procedure that has had caching enabled for which you want to assign pre- and or post-actions.
7. Select the Caching tab.
8. Under Advanced, choose Full Refresh Mode.
9. For the Pre-Refresh or Post-Refresh Action fields, or both, specify a procedure that exists in the Studio resource tree and has no parameters.
10. Save the cache settings. After cache settings are saved, each cached resource appears with a lightning-bolt icon in the Studio resource tree to show that the resource is cached.
11. If you have data type incompatibilities between your view and your data storage type, see “Cache Data Type Mapping” in the TDV Reference Guide.