The ad-hoc cache is used to cache frequently regenerated HareScript data. It works by invoking GetAdhocCached with a record as a key and a callback function to generate the data. The cache will see if it has the data for the specified key, and if not, will invoke the callback to generate the data.
The key is combined with the calling library to create a hash for the cache key. This prevents adhoc cache calls made from different libraries from having conflicting keys but will also generally require you to use the same route (or at least the same library) to an adhoc cache call.
When multiple jobs in the same WebHare process request the same key they will all wait for one job to actually do the calculation, and then all share the result.
+A: 2014-10-13 (286) 15:22:01.559'
- The adhoc cache is synchronized between all HareScript jobs in the same process and thus not 'free' to call! Overusing the adhoc cache may actually slow down your application - profiling is recommended.
- The adhoc cache key must match exactly for data to match. You should be especially careful when passing date/times to the adhoc cache derived from GetCurrentDatetime - if necessary, round them first using GetRoundedDatetime.
- The adhoc cache is shared at the WebHare process level:
- All dynamic pages run inside the webserver and share their cache
- Managed tasks and publications may or may not share a cache
- Runscript (wh run) tasks will not share their cache between runs.
- Caching blobs that are selected from the database will cause them to be downloaded instead of just a reference being held. An indication of this is usually StoreAdhocCached appearing high in your performance profiles. If your cache stores images or files, consider converting them first to URLs using the image cache.