Transaction

Classin corecompute-sdk-cpp 0.7.0View source

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

A cache transaction resulting from a transactional lookup.

This type is returned from TransactionLookupBuilder::execute() and provides access to the result of the lookup as well as methods to insert or update cached items when required.

Methods

cancel_insert_or_update

View source
tl::expected<void, CacheError> fastly::cache::core::Transaction::cancel_insert_or_update() const

Cancels the obligation for this transaction client to insert or update a cache item.

If there are concurrent transactional lookups that were blocked waiting on this client to provide the item, one of them will be chosen to be unblocked and given the must_insert_or_update() obligation.

This method should only be called when must_insert_or_update() is true; otherwise, a CacheError::InvalidOperation will be returned.

Returns

tl::expected<void, CacheError>
std::optional<Found> fastly::cache::core::Transaction::found() const

Returns a Found object for this cache item, if one is available.

Even if an object is found, the cache item might be stale and require updating. Use Transaction::must_insert_or_update() to determine whether this transaction client is expected to update the cached item.

Returns

std::optional<Found>
TransactionInsertBuilder fastly::cache::core::Transaction::insert(std::chrono::nanoseconds max_age) &&

Returns a TransactionInsertBuilder that will perform a transactional cache insertion.

This method should only be called when must_insert_or_update() is true; otherwise, a CacheError::InvalidOperation will be returned when attempting to execute the insertion.

Parameters

max_age: std::chrono::nanoseconds

Returns

lookup

static

Overload 1 of 2

static TransactionLookupBuilder fastly::cache::core::Transaction::lookup(std::span<const std::uint8_t> key)
View source

Returns a TransactionLookupBuilder that will perform a transactional cache lookup.

Parameters

key: std::span<const std::uint8_t>

Returns

Overload 2 of 2

static TransactionLookupBuilder fastly::cache::core::Transaction::lookup(std::string_view key)
View source

Transactional cache lookup with string key.

Parameters

key: std::string_view

Returns

must_insert

View source
bool fastly::cache::core::Transaction::must_insert() const

Returns true if a usable cached item was not found, and this transaction client is expected to insert one.

Use insert() to insert the cache item, or cancel_insert_or_update() to exit the transaction without providing an item.

Returns

bool

must_insert_or_update

View source
bool fastly::cache::core::Transaction::must_insert_or_update() const

Returns true if a fresh cache item was not found, and this transaction client is expected to insert a new item or update a stale item.

Use:

Returns

bool
TransactionUpdateBuilder fastly::cache::core::Transaction::update(std::chrono::nanoseconds max_age) &&

Returns a TransactionUpdateBuilder that will perform a transactional cache update.

Updating an item freshens it by updating its metadata, e.g. its age, without changing the object itself.

This method should only be called when must_insert_or_update() is true AND the item is found. Otherwise, a CacheError::InvalidOperation will be returned when attempting to execute the update.

Important note: The TransactionUpdateBuilder will replace ALL of the configuration in the underlying cache item; if any configuration is not set on the builder, it will revert to the default value.

Parameters

max_age: std::chrono::nanoseconds

Returns