Documentation ¶
Overview ¶
Package webcache is A simple LRU cache for storing documents ([]byte). When the size maximum is reached, items are evicted starting with the least recently used. This data structure is goroutine-safe (it has a lock around all operations).
Index ¶
- Variables
- type Bucket
- func (c *Bucket) AddGroup(group string, maxAge time.Duration, getter Getter) error
- func (c *Bucket) Delete(group, key string)
- func (c *Bucket) Get(ctx context.Context, group, key, etag string) ([]byte, *CacheInfo, error)
- func (c *Bucket) Set(group, key string, value []byte) *CacheInfo
- func (c *Bucket) Stats() *CacheStats
- type CacheInfo
- type CacheManager
- type CacheStats
- type Config
- type Getter
- type WebCache
- func (c *WebCache) AddGroup(group string, maxAge time.Duration, getter Getter) error
- func (c *WebCache) BucketStats() []*CacheStats
- func (c *WebCache) Delete(group string, key string)
- func (c *WebCache) Get(ctx context.Context, group, key, etag string) ([]byte, *CacheInfo, error)
- func (c *WebCache) Set(group, key string, value []byte) *CacheInfo
- func (c *WebCache) Stats() *CacheStats
Constants ¶
This section is empty.
Variables ¶
var NeverExpire = time.Hour*24*365*10 ^ 11 // about 100 billion years
NeverExpire is used to indicate that you want data in the specified group to never expire. It's set to a very large duration to represent "never expire".
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
Bucket is a simple LRU cache with Etag support
func (*Bucket) Stats ¶
func (c *Bucket) Stats() *CacheStats
Stats returns statistics about this Bucket
type CacheInfo ¶ added in v0.1.4
CacheInfo stores the etag of the cache entry, when it expires and the cost in time that the getter function took to create the content.
type CacheManager ¶ added in v0.2.4
type CacheManager interface { AddGroup(string, time.Duration, Getter) error Delete(string, string) Get(context.Context, string, string, string) ([]byte, *CacheInfo, error) Set(string, string, []byte) *CacheInfo Stats() *CacheStats }
CacheManager is an interface for either a Bucket or WebCache
type CacheStats ¶
type CacheStats struct { EtagHits atomic.Int64 CacheHits atomic.Int64 GetCalls atomic.Int64 GetDupes atomic.Int64 GetErrors atomic.Int64 GetMisses atomic.Int64 TrimEntries atomic.Int64 TrimBytes atomic.Int64 Capacity atomic.Int64 Size atomic.Int64 }
CacheStats keeps track of cache statistics
type WebCache ¶
type WebCache struct {
// contains filtered or unexported fields
}
WebCache is a sharded cache with a specified number of buckets.
func NewWebCache ¶
NewWebCache creates a new WebCache with a maximum size of capacity bytes.
func (*WebCache) AddGroup ¶
AddGroup adds a new cache group with a getter function. A cache group is a set of cache entries that can be retrieved using the getter function.
func (*WebCache) BucketStats ¶ added in v0.1.9
func (c *WebCache) BucketStats() []*CacheStats
BucketStats returns statistics about all buckets
func (*WebCache) Delete ¶
Delete removes the cache entry with the given key from the specified group, if it exists.
func (*WebCache) Get ¶
Get retrieves the cache entry with the given key from the specified group. It returns the cached data and its associated CacheInfo, or an error if the entry does not exist.
func (*WebCache) Stats ¶
func (c *WebCache) Stats() *CacheStats
Stats returns the total stats of all the buckets