Skip to content

Module hb_cache_control.erl

Cache control logic for the AO-Core resolver.

Description

It derives cache settings from request, response, execution-local node Opts, as well as the global node Opts. It applies these settings when asked to maybe store/lookup in response to a request.

Function Index

cache_binary_result_test/0*
cache_message_result_test/0*
cache_source_to_cache_settings/2*Convert a cache source to a cache setting.
derive_cache_settings/2*Derive cache settings from a series of option sources and the opts, honoring precidence order.
dispatch_cache_write/4*Dispatch the cache write to a worker process if requested.
empty_message_list_test/0*
exec_likely_faster_heuristic/3*Determine whether we are likely to be faster looking up the result in our cache (hoping we have it), or executing it directly.
hashpath_ignore_prevents_storage_test/0*
is_explicit_lookup/3*
lookup/3*
maybe_lookup/3Handles cache lookup, modulated by the caching options requested by the user.
maybe_set/3*Takes a key and two maps, returning the first map with the key set to the value of the second map _if_ the value is not undefined.
maybe_store/4Write a resulting M3 message to the cache if requested.
message_source_cache_control_test/0*
message_without_cache_control_test/0*
msg_precidence_overrides_test/0*
msg_with_cc/1*
multiple_directives_test/0*
necessary_messages_not_found_error/3*Generate a message to return when the necessary messages to execute a cache lookup are not found in the cache.
no_cache_directive_test/0*
no_store_directive_test/0*
only_if_cached_directive_test/0*
only_if_cached_not_found_error/3*Generate a message to return when only_if_cached was specified, and we don't have a cached result.
opts_override_message_settings_test/0*
opts_source_cache_control_test/0*
opts_with_cc/1*
specifiers_to_cache_settings/1*Convert a cache control list as received via HTTP headers into a normalized map of simply whether we should store and/or lookup the result.

Function Details

cache_binary_result_test/0 *

cache_binary_result_test() -> any()

cache_message_result_test/0 *

cache_message_result_test() -> any()

cache_source_to_cache_settings/2 *

cache_source_to_cache_settings(Msg, Opts) -> any()

Convert a cache source to a cache setting. The setting must always be directly in the source, not an AO-Core-derivable value. The to_cache_control_map function is used as the source of settings in all cases, except where an Opts specifies that hashpaths should not be updated, which leads to the result not being cached (as it may be stored with an incorrect hashpath).

derive_cache_settings/2 *

derive_cache_settings(SourceList, Opts) -> any()

Derive cache settings from a series of option sources and the opts, honoring precidence order. The Opts is used as the first source. Returns a map with store and lookup keys, each of which is a boolean.

For example, if the last source has a no_store, the first expresses no preference, but the Opts has cache_control => [always], then the result will contain a store => true entry.

dispatch_cache_write/4 *

dispatch_cache_write(Msg1, Msg2, Msg3, Opts) -> any()

Dispatch the cache write to a worker process if requested. Invoke the appropriate cache write function based on the type of the message.

empty_message_list_test/0 *

empty_message_list_test() -> any()

exec_likely_faster_heuristic/3 *

exec_likely_faster_heuristic(Msg1, Msg2, Opts) -> any()

Determine whether we are likely to be faster looking up the result in our cache (hoping we have it), or executing it directly.

hashpath_ignore_prevents_storage_test/0 *

hashpath_ignore_prevents_storage_test() -> any()

is_explicit_lookup/3 *

is_explicit_lookup(Msg1, X2, Opts) -> any()

lookup/3 *

lookup(Msg1, Msg2, Opts) -> any()

maybe_lookup/3

maybe_lookup(Msg1, Msg2, Opts) -> any()

Handles cache lookup, modulated by the caching options requested by the user. Honors the following Opts cache keys: only_if_cached: If set and we do not find a result in the cache, return an error with a Cache-Status of miss and a 504 Status. no_cache: If set, the cached values are never used. Returns continue to the caller.

maybe_set/3 *

maybe_set(Map1, Map2, Opts) -> any()

Takes a key and two maps, returning the first map with the key set to the value of the second map if the value is not undefined.

maybe_store/4

maybe_store(Msg1, Msg2, Msg3, Opts) -> any()

Write a resulting M3 message to the cache if requested. The precedence order of cache control sources is as follows: 1. The Opts map (letting the node operator have the final say). 2. The Msg3 results message (granted by Msg1's device). 3. The Msg2 message (the user's request). Msg1 is not used, such that it can specify cache control information about itself, without affecting its outputs.

message_source_cache_control_test/0 *

message_source_cache_control_test() -> any()

message_without_cache_control_test/0 *

message_without_cache_control_test() -> any()

msg_precidence_overrides_test/0 *

msg_precidence_overrides_test() -> any()

msg_with_cc/1 *

msg_with_cc(CC) -> any()

multiple_directives_test/0 *

multiple_directives_test() -> any()

necessary_messages_not_found_error/3 *

necessary_messages_not_found_error(Msg1, Msg2, Opts) -> any()

Generate a message to return when the necessary messages to execute a cache lookup are not found in the cache.

no_cache_directive_test/0 *

no_cache_directive_test() -> any()

no_store_directive_test/0 *

no_store_directive_test() -> any()

only_if_cached_directive_test/0 *

only_if_cached_directive_test() -> any()

only_if_cached_not_found_error/3 *

only_if_cached_not_found_error(Msg1, Msg2, Opts) -> any()

Generate a message to return when only_if_cached was specified, and we don't have a cached result.

opts_override_message_settings_test/0 *

opts_override_message_settings_test() -> any()

opts_source_cache_control_test/0 *

opts_source_cache_control_test() -> any()

opts_with_cc/1 *

opts_with_cc(CC) -> any()

specifiers_to_cache_settings/1 *

specifiers_to_cache_settings(CCSpecifier) -> any()

Convert a cache control list as received via HTTP headers into a normalized map of simply whether we should store and/or lookup the result.