TransactionInsertBuilder

Classin corecompute-sdk-cpp 0.7.0View source

Include fastly/cache/core.h to use this class.

A builder-style API for configuring a transactional cache insertion.

This builder is used to insert a new item into the cache during a transaction. All builder methods consume the builder and return it for method chaining.

Methods

deliver_node_max_age

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::deliver_node_max_age(std::chrono::nanoseconds duration) &&

Sets the maximum time the cached item may live on a deliver node in a POP.

Parameters

duration: std::chrono::nanoseconds

Returns

tl::expected<http::StreamingBody, CacheError> fastly::cache::core::TransactionInsertBuilder::execute() &&

Begin the insertion, returning a StreamingBody for providing the cached object itself.

For the insertion to complete successfully, the object must be written into the StreamingBody, and then StreamingBody::finish must be called. If the StreamingBody is dropped before calling StreamingBody::finish, the insertion is considered incomplete, and any concurrent lookups that may be reading from the object as it is streamed into the cache may encounter a streaming error.

Returns

tl::expected<http::StreamingBody, CacheError>

execute_and_stream_back

View source
tl::expected<std::pair<http::StreamingBody, Found>, CacheError> fastly::cache::core::TransactionInsertBuilder::execute_and_stream_back() &&

Begin the insertion, and provide a Found object that can be used to stream out of the newly-inserted object.

For the insertion to complete successfully, the object must be written into the StreamingBody, and then StreamingBody::finish must be called. If the StreamingBody is dropped before calling StreamingBody::finish, the insertion is considered incomplete, and any concurrent lookups that may be reading from the object as it is streamed into the cache may encounter a streaming error.

The returned Found object allows the client inserting a cache item to efficiently read back the contents of that item, avoiding the need to buffer contents for copying to multiple destinations. This pattern is commonly required when caching an item that also must be provided to, e.g., the client response.

Returns

tl::expected<std::pair<http::StreamingBody, Found>, CacheError>

initial_age

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::initial_age(std::chrono::nanoseconds age) &&

Sets the initial age of the cached item, to be used in freshness calculations. The initial age is 0 by default.

Parameters

age: std::chrono::nanoseconds

Returns

known_length

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::known_length(std::uint64_t length) &&

Sets the size of the cached item, in bytes, when known prior to actually providing the bytes.

It is preferable to provide a length, if possible. Clients that begin streaming the item’s contents before it is completely provided will see the promised length which allows them to, for example, use content-length instead of transfer-encoding: chunked if the item is used as the body of a Request or Response.

Parameters

length: std::uint64_t

Returns

on_behalf_of

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::on_behalf_of(std::string service) &&

Perform this insert on behalf of another service, using its data store.

Internal / Privileged This operation is privileged, and attempts to use this functionality without proper privileges will cause errors. If you are interested in having two or more of your services share the same cache, please talk to your Fastly account representative. While we have no plans to offer this ability widely – this capability is only currently allowed for Fastly-internal services – we may revisit this decision given sufficient customer input.

Parameters

service: std::string

Returns

sensitive_data

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::sensitive_data(bool is_sensitive) &&

Enable or disable PCI/HIPAA-compliant non-volatile caching.

By default, this is false.

See the Fastly PCI-Compliant Caching and Delivery documentation for details.

Parameters

is_sensitive: bool

Returns

stale_while_revalidate

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::stale_while_revalidate(std::chrono::nanoseconds duration) &&

Sets the stale-while-revalidate period for the cached item, which is the time for which the item can be safely used despite being considered stale.

Having a stale-while-revalidate period provides a signal that the cache should be updated (or its contents otherwise revalidated for freshness) asynchronously, while the stale cached item continues to be used, rather than blocking on updating the cached item. The methods Found::is_usable and Found::is_stale can be used to determine the current state of a found item.

The stale-while-revalidate period is 0 by default.

Parameters

duration: std::chrono::nanoseconds

Returns

surrogate_keys

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::surrogate_keys(std::vector<std::string> keys) &&

Sets the surrogate keys that can be used for purging this cached item.

Surrogate key purges are the only means to purge specific items from the cache. At least one surrogate key must be set in order to remove an item without performing a purge-all, waiting for the item’s TTL to elapse, or overwriting the item with crate::cache::core::insert().

Surrogate keys must contain only printable ASCII characters (those between 0x21 and 0x7E, inclusive). Any invalid keys will be ignored.

See the Fastly surrogate keys guide for details.

Parameters

keys: std::vector<std::string>

Returns

user_metadata

View source
TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::user_metadata(std::vector<std::uint8_t> metadata) &&

Sets the user-defined metadata to associate with the cached item.

Parameters

metadata: std::vector<std::uint8_t>

Returns

TransactionInsertBuilder fastly::cache::core::TransactionInsertBuilder::vary_by(std::vector<std::string> headers) &&

Sets the list of headers that must match when looking up this cached item.

The header values must be provided by calling TransactionLookupBuilder::header() or TransactionLookupBuilder::header_values(). The header values may be a subset or superset of the header names supplied here.

Parameters

headers: std::vector<std::string>

Returns