Ad-Hoc cache

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.


LOADLIB "wh::datetime.whlib";
LOADLIB "module::system/cache.whlib";

  RETURN [ value := [[ a := GetCurrentDateTime() ]]
         , ttl := 15 * 60000 // 15 mins

RECORD ARRAY items := GetAdhocCached([ type := "data" ], PTR GetCachedData());


    +A: 2014-10-13 (286) 15:22:01.559'