Documentation
¶
Index ¶
- Variables
- func DeclaredTag(subgraph, tag string) string
- func DecodeEntry(b []byte) (value []byte, surrogateKeys []string, err error)
- func EncodeEntry(value []byte, surrogateKeys []string) []byte
- func Key(entity, selection Digest) string
- func MergeSurrogateKeys(dst []string, src ...[]string) []string
- func PrivateKey(entity, selection, privateID Digest) string
- func SortSurrogateKeys(surrogateKeys []string)
- func SubgraphSurrogateKey(subgraph string) string
- func SubgraphTag(subgraph string) string
- func TTL(headers http.Header, defaultTTL time.Duration) (ttl time.Duration, private bool, ok bool)
- func TypeSurrogateKey(subgraph, typeName string) string
- func TypeTag(subgraph, typeName string) string
- func ValidDeclaredSurrogateKey(tag string) bool
- type Cache
- type Digest
- type Item
- type SetManyError
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingTTL = errors.New("cache item requires a positive TTL") ErrNoKeys = errors.New("response cache lookup requires at least one key") ErrNoItems = errors.New("response cache write requires at least one item") )
var ErrEntryFormat = errors.New("cache entry is not in a known format")
Functions ¶
func DeclaredTag ¶ added in v2.20.0
A subgraph name carrying the separator would otherwise spell another subgraph's tag, so separators within the scope are doubled and the single one after it is what ends the scope.
func DecodeEntry ¶ added in v2.22.0
DecodeEntry returns the value as a subslice of b.
func EncodeEntry ¶ added in v2.22.0
func MergeSurrogateKeys ¶ added in v2.22.0
MergeSurrogateKeys appends every tag of src not already in dst, first seen order.
func PrivateKey ¶ added in v2.22.0
PrivateKey builds the key for one entity within one fetch as seen by one user.
func SortSurrogateKeys ¶ added in v2.22.0
func SortSurrogateKeys(surrogateKeys []string)
SortSurrogateKeys groups by tier, coarsest first, keeping the order within a tier.
func SubgraphSurrogateKey ¶ added in v2.22.0
func SubgraphTag ¶ added in v2.20.0
func TypeSurrogateKey ¶ added in v2.22.0
func ValidDeclaredSurrogateKey ¶ added in v2.22.0
ValidDeclaredSurrogateKey reports whether a declared tag can go in a header. One spelled like a derived key passes: the header is the CDN's contract and carries what the subgraph declared, the index files it as declared.
Types ¶
type Cache ¶
type Cache interface {
// GetMany looks up every key and returns the ones it found, keyed by the
// key they were asked for, with the SurrogateKeys they were stored with. A
// miss is simply absent, never an error and never a zero Item.
GetMany(ctx context.Context, keys []string) (map[string]Item, error)
// SetMany stores every item, all of which must carry a positive TTL. When
// items contains the same key twice, the last one wins. An error means an
// unspecified subset of the items may already have been stored.
// In case any of the passed ttls are invalid, SetMany should return
// without saving any items that may have valid ttl values.
SetMany(ctx context.Context, items []Item) error
}
Cache is a batch oriented key/value cache.
type Digest ¶ added in v2.22.0
Digest is the SHA-256 of one input to a key. Collision resistant, so two inputs cannot end up on one key, and fixed size, so raw inputs never reach the store.
func DigestBytes ¶ added in v2.22.0
func DigestParts ¶ added in v2.22.0
DigestParts digests the parts in order with a zero byte between them, so a byte moving from the end of one part to the start of the next cannot go unnoticed.
func DigestString ¶ added in v2.22.0
type Item ¶
type Item struct {
// Key is the key the entry is stored under, exactly as GetMany was asked
// for it, so an Item carries enough to be acted on once it has been taken
// out of the map it came in.
Key string
// Value is the cached bytes. An entry with an empty Value is still an
// entry: GetMany omitting the key is the only thing that means a miss.
Value []byte
// TTL is how long the entry should live when passed to SetMany, and how
// much of that life it has left when returned by GetMany, so the same key
// comes back with less of it on every lookup. It is always positive in
// both directions: SetMany refuses an item without a positive TTL, and
// GetMany treats an entry with nothing left to live, or one it finds with
// no expiry attached at all, as a miss rather than a hit.
TTL time.Duration
// Tags are the cache tags the entry was stored under, a secondary index
// naming what the entry is about so it can later be found by something other
// than its key for invalidation.
Tags []string
// Surrogate keys are what a client response carries so a CDN can purge by them.
// Stored with the value and returned by GetMany.
SurrogateKeys []string
}
Item is a single cache entry, both on the way in through SetMany and on the way back out of GetMany.
type SetManyError ¶
type SetManyError struct {
// This depicts the known stored keys in a case of a partial write
// this means that some more keys could have been written but there is no way to know
// because the client did not receive a response
KnownStoredKeys []string
Err error
}
func (*SetManyError) Error ¶
func (e *SetManyError) Error() string
func (*SetManyError) Unwrap ¶
func (e *SetManyError) Unwrap() error