core
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
| Found | Found represents a cached object found by a cache lookup. |
| LookupOptions | LookupOptions control the behavior of cache lookups and the objects returned. |
| Transaction | Transaction represents a construct to coordinate concurrent actions for the same cache key. |
| WriteOptions | WriteOptions control the behavior of cache inserts and updates. TTL is required, but all other fields are optional. |
Interfaces
| WriteCloseAbandoner | WriteCloseAbandoner 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
| Insert | Insert 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. |
| Lookup | Lookup 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. |
| NewTransaction | NewTransaction creates a new cache transaction for the given key. |
Variables
Default: errors.New("cache: invalid argument")
ErrInvalidArgument is returned when an argument passed to a function is invalid.
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.
Default: errors.New("cache: operation limit exceeded")
ErrLimitExceeded is returned when a cache operation exceeds the limits allowed for this service.
Default: errors.New("cache: object not found")
ErrNotFound is returned when a cache lookup fails to find a cached object with the provided key.
Default: errors.New("cache: unexpected error")
ErrUnexpected is returned when an unexpected error occurs.
Default: errors.New("cache: operation not supported")
ErrUnsupported is returned when a cache operation is not supported.