Skip to content

Module dev_cache.erl

A device that looks up an ID from a local store and returns it, honoring the accept key to return the correct format.

Description

The cache also supports writing messages to the store, if the node message has the writer's address in its cache_writers key.

Function Index

cache_write_binary_test/0*Ensure that we can write direct binaries to the cache.
cache_write_message_test/0*Test that the cache can be written to and read from using the hb_cache API.
is_trusted_writer/2*Verify that the request originates from a trusted writer.
link/3Link a source to a destination in the cache.
read/3Read data from the cache.
read_from_cache/2*Read data from the cache via HTTP.
setup_test_env/0*Create a test environment with a local store and node.
write/3Write data to the cache.
write_single/2*Helper function to write a single data item to the cache.
write_to_cache/3*Write data to the cache via HTTP.

Function Details

cache_write_binary_test/0 *

cache_write_binary_test() -> any()

Ensure that we can write direct binaries to the cache.

cache_write_message_test/0 *

cache_write_message_test() -> any()

Test that the cache can be written to and read from using the hb_cache API.

is_trusted_writer/2 *

is_trusted_writer(Req, Opts) -> any()

Verify that the request originates from a trusted writer. Checks that the single signer of the request is present in the list of trusted cache writer addresses specified in the options.

link/3

link(Base, Req, Opts) -> any()

Link a source to a destination in the cache.

read/3

read(M1, M2, Opts) -> any()

Read data from the cache. Retrieves data corresponding to a key from a local store. The key is extracted from the incoming message under <<"target">>. The options map may include store configuration. If the "accept" header is set to <<"application/aos-2">>, the result is converted to a JSON structure and encoded.

read_from_cache/2 *

read_from_cache(Node, Path) -> any()

Read data from the cache via HTTP. Constructs a GET request using the provided path, sends it to the node, and returns the response.

setup_test_env/0 *

setup_test_env() -> any()

Create a test environment with a local store and node. Ensures that the required application is started, configures a local file-system store, resets the store for a clean state, creates a wallet for signing requests, and starts a node with the store and trusted cache writer configuration.

write/3

write(M1, M2, Opts) -> any()

Write data to the cache. Processes a write request by first verifying that the request comes from a trusted writer (as defined by the cache_writers configuration in the options). The write type is determined from the message ("single" or "batch") and the data is stored accordingly.

write_single/2 *

write_single(Msg, Opts) -> any()

Helper function to write a single data item to the cache. Extracts the body, location, and operation from the message. Depending on the type of data (map or binary) or if a link operation is requested, it writes the data to the store using the appropriate function.

write_to_cache/3 *

write_to_cache(Node, Data, Wallet) -> any()

Write data to the cache via HTTP. Constructs a write request message with the provided data, signs it with the given wallet, sends it to the node, and verifies that the response indicates a successful write.