Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTooBig is returned by Cache::Put when when the item size is bigger than the // cache size limit. ErrTooBig = errors.New("item bigger than the cache size limit") )
Functions ¶
func NewFsCache ¶
NewFsCache returns a new instance of a filesystem-based cache rooted at `dir`, with a maximum size of `maxSizeBytes` bytes.
Types ¶
type Cache ¶
type Cache interface { // Put stores a stream of `size` bytes from `r` into the cache. If `expectedSha256` is // not the empty string, and the contents don't match it, an error is returned Put(key string, size int64, expectedSha256 string, r io.Reader) error // Get writes the content of the cache item stored under `key` to `w`. If the item is // not found, it returns ok = false. Get(key string, w http.ResponseWriter) (ok bool, err error) Contains(key string) (ok bool, err error) // Stats MaxSize() int64 CurrentSize() int64 NumItems() int }
Cache is the interface for a generic blob storage backend. Implementers should handle locking internally.
type EvictCallback ¶
EvictCallback is the type of callbacks that are invoked when items are evicted.
type HTTPCache ¶
type HTTPCache interface { CacheHandler(w http.ResponseWriter, r *http.Request) StatusPageHandler(w http.ResponseWriter, r *http.Request) }
HTTPCache ...
func NewHTTPCache ¶
func NewHTTPCache(cacheDir string, maxBytes int64, accessLogger logger, errorLogger logger) HTTPCache
NewHTTPCache returns a new instance of the cache. accessLogger will print one line for each HTTP request to the cache. errorLogger will print unexpected server errors. Inexistent files and malformed URLs will not be reported.
type SizedLRU ¶
type SizedLRU interface { Add(key Key, value SizedItem) (ok bool) Get(key Key) (value SizedItem, ok bool) Remove(key Key) Len() int CurrentSize() int64 MaxSize() int64 }
SizedLRU is an LRU cache that will keep its total size below maxSize by evicting items. SizedLRU is not thread-safe.
func NewSizedLRU ¶
func NewSizedLRU(maxSize int64, onEvict EvictCallback) SizedLRU
NewSizedLRU returns a new sizedLRU cache