Documentation
¶
Overview ¶
Package cache provides a size-bounded, LRU-evicting disk cache that implements the httpcache.Cache interface. Responses are stored under a per-hostname subdirectory so they can be cleared by API name.
Index ¶
- Constants
- type Breakdown
- type DiskCache
- func (c *DiskCache) Clear(host string) error
- func (c *DiskCache) ClearNamespacePrefix(prefix string) (int, error)
- func (c *DiskCache) ClearNamespaces(namespaces []string) error
- func (c *DiskCache) Delete(key string)
- func (c *DiskCache) Get(key string) ([]byte, bool)
- func (c *DiskCache) Info() (*Info, error)
- func (c *DiskCache) Set(key string, data []byte)
- func (c *DiskCache) WaitEvict()
- type Info
Constants ¶
const DefaultMaxBytes = 100 * 1024 * 1024
DefaultMaxBytes is the default maximum cache size (100 MiB).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiskCache ¶
type DiskCache struct {
// contains filtered or unexported fields
}
DiskCache is a file-system backed HTTP response cache. It satisfies the httpcache.Cache interface (Get/Set/Delete) and additionally provides Info and Clear for the "restish cache" subcommands.
func New ¶
New returns a DiskCache rooted at dir with the given size cap. dir is created if it does not exist.
func NewWithLogger ¶
func NewWithLogger(dir string, maxBytes int64, namespace string, logger io.Writer) (*DiskCache, error)
NewWithLogger returns a DiskCache that writes non-fatal cache diagnostics to logger when provided.
func (*DiskCache) Clear ¶
Clear deletes HTTP response cache entries. If host is non-empty, only entries stored under the <host> subdirectory are removed (i.e. responses for one API).
func (*DiskCache) ClearNamespacePrefix ¶
ClearNamespacePrefix deletes entries for every namespace with prefix and returns the number of namespace directories removed.
func (*DiskCache) ClearNamespaces ¶
ClearNamespaces deletes entries for the given cache namespaces across all hosts. It is used for API-specific clearing because one registered API can have multiple profile base URLs or operation hosts that share a hostname with other APIs.
func (*DiskCache) Get ¶
Get returns the cached bytes for key, if present, and updates the file's mtime (used as LRU timestamp).