Modulecompute-sdk-go v1.11.0

github.com/fastly/compute-sdk-go/cache/core

Package core provides the Fastly Core Cache API.

This package exposes the primitive operations required to implement high-performance cache applications with advanced features such as request collapsing, streaming miss, revalidation, and surrogate key purging.

While this API contains affordances for some HTTP caching concepts such as Vary headers and stale-while-revalidate, this API is not suitable for HTTP caching out-of-the-box. Future SDK releases will add a more customizable HTTP Cache API with support for customizable read-through caching, freshness lifetime inference, conditional request evaluation, automatic revalidation, and more.

Cached items in this API consist of:

  • A cache key: up to 4096 bytes of arbtirary data that identify a cached object. The cache key may not uniquely identify an item; headers can be used to augment the key when multiple items are associated with the same key.

  • General metadata, such as expiry data (item age, when to expire, and surrogate keys for purging).

  • User-controlled metadata: arbitrary bytes stored alongside the cached object that can be updated when revalidating the cached object.

  • The object itself: arbitrary bytes read via an io.ReadCloser and written via a WriteCloseAbandoner.

In the simplest cases, the top-level Insert and Lookup functions are used for one-off operations on a cached object, and are appropriate when request collapsing and revalidation capabilities are not required.

The API also supports more complex uses via Transaction, which can collapse concurrent lookups to the same item, including coordinating revalidation.

Structs

FoundFound represents a cached object found by a cache lookup.
LookupOptionsLookupOptions control the behavior of cache lookups and the objects returned.
TransactionTransaction represents a construct to coordinate concurrent actions for the same cache key.
WriteOptionsWriteOptions control the behavior of cache inserts and updates. TTL is required, but all other fields are optional.

Interfaces

WriteCloseAbandonerWriteCloseAbandoner is an interface returned by cache insert operations. It is an io.WriteCloser that also supports abandoning the stream. When Abandon is called, the insert operation is canceled and content written is not saved into the cache.

Functions

InsertInsert creates a WriteCloseAbandoner used for inserting an object into the cache for the given key. For the insertion to complete successfully, the object must be fully written to the writer and its Close method called.
LookupLookup performs a simple, non-transactional lookup for the given key. If the key is not cached, [ErrNotFound] is returned. Keys can be up to 4096 bytes in length.
NewTransactionNewTransaction creates a new cache transaction for the given key.

Variables

ErrInvalidArgument

errorView source

Default: errors.New("cache: invalid argument")

ErrInvalidArgument is returned when an argument passed to a function is invalid.

ErrInvalidOperation

errorView source

Default: errors.New("cache: invalid operation")

ErrInvalidOperation is returned when an operation to be performed is not valid given the state of the cached object.

ErrLimitExceeded

errorView source

Default: errors.New("cache: operation limit exceeded")

ErrLimitExceeded is returned when a cache operation exceeds the limits allowed for this service.

ErrNotFound

errorView source

Default: errors.New("cache: object not found")

ErrNotFound is returned when a cache lookup fails to find a cached object with the provided key.

ErrUnexpected

errorView source

Default: errors.New("cache: unexpected error")

ErrUnexpected is returned when an unexpected error occurs.

ErrUnsupported

errorView source

Default: errors.New("cache: operation not supported")

ErrUnsupported is returned when a cache operation is not supported.