Found
12345678910111213141516type Found struct { Key []byte
TTL time.Duration
Length uint64
Age time.Duration
StaleWhileRevalidate time.Duration
Hits uint64
Body io.ReadCloser // contains filtered or unexported fields}Found represents a cached object found by a cache lookup.
Fields
TTL is the time for which the cached object is considered fresh.
Length is the length of the cached object in bytes, if known. The length of the cached item may be unknown if the item is currently being streamed into the cache without a fixed length.
Age is the age of the cached object at lookup time.
StaleWhileRevalidate
time.DurationStaleWhileRevalidate is the period of time that the cached object can be served stale while revalidation takes place.
This provides a signal that the cache should be updated (or its contents otherwise revalidated for freshness) asynchronously, while the stale cached object continues to be used, rather than blocking on updating the cached object. The default stale-while-revalidate period is zero.
Hits is the number of times the cached object has been served. This count only reflects the view of the server that supplied the cached object. Due to clustering, this count may vary between potentially many servers within the data center where the item is cached. See the clustering documentation for details: https://developer.fastly.com/learning/vcl/clustering/
Body
io.ReadCloserBody is an io.ReadCloser for the cached object. It must be closed when finished.
Methods
GetRange
View sourceGetRange returns an io.ReadCloser for the provided range of bytes. The Found's Body must be closed before calling this function, or it will return [ErrInvalidOperation].
Parameters
- from: uint64
- to: uint64
Returns
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647const ( key = "my_key" contents = "my cached object")
w, err := core.Insert([]byte(key), core.WriteOptions{ TTL: time.Hour, SurrogateKeys: []string{key}, Length: uint64(len(contents)),})if err != nil { panic(err)}if _, err := io.WriteString(w, contents); err != nil { panic(err)}if err := w.Close(); err != nil { panic(err)}
f, err := core.Lookup([]byte("my_key"), core.LookupOptions{})if err != nil { panic(err)}
if err := f.Body.Close(); err != nil { panic(err)}
_, err = f.GetRange(3, 1)if err == nil { panic("accepted invalid range")}
body, err := f.GetRange(3, 0)if err == nil { panic("accepted invalid range")}cachedStr, err := io.ReadAll(body)if err != nil { panic(err)}if string(cachedStr) != "cached object" { panic(fmt.Sprintf("got: %q, want: %q", cachedStr, "cached object"))}
fmt.Printf("The cached value was: %s", cachedStr)Stale
View sourcefunc (f *Found) Stale() boolStale returns true if the cached object is stale.
Returns
Usable
View sourcefunc (f *Found) Usable() boolUsable returns true if the cached object is usable.
Returns
UserMetadata
View sourcefunc (f *Found) UserMetadata() ([]byte, error)UserMetadata returns user-provided metadata associated with the cached object. It will return an empty slice if no metadata was provided when the object was inserted.
Returns