Documentation
¶
Overview ¶
Package freecache provides a high-performance, zero-GC overhead implementation of httpcache.Cache using github.com/coocood/freecache as the underlying storage.
This backend is suitable for applications that need to cache millions of entries with minimal GC overhead and automatic memory management with LRU eviction.
Example usage:
cache := freecache.New(100 * 1024 * 1024) // 100MB cache transport := httpcache.NewTransport(cache) client := transport.Client()
Index ¶
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Delete(key string)
- func (c *Cache) EntryCount() int64
- func (c *Cache) EvacuateCount() int64
- func (c *Cache) ExpiredCount() int64
- func (c *Cache) Get(key string) ([]byte, bool)
- func (c *Cache) HitRate() float64
- func (c *Cache) ResetStatistics()
- func (c *Cache) Set(key string, value []byte)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is an implementation of httpcache.Cache that uses freecache for storage. It provides zero-GC overhead and automatic LRU eviction when cache is full.
func New ¶
New creates a new Cache with the specified size in bytes. The cache size will be set to 512KB at minimum.
For large cache sizes, you may want to call debug.SetGCPercent() with a lower value to reduce GC overhead.
Example:
import "runtime/debug" cache := freecache.New(100 * 1024 * 1024) // 100MB debug.SetGCPercent(20)
func (*Cache) EntryCount ¶
EntryCount returns the number of entries currently in the cache
func (*Cache) EvacuateCount ¶
EvacuateCount returns the number of times entries were evicted due to cache being full
func (*Cache) ExpiredCount ¶
ExpiredCount returns the number of times entries expired
func (*Cache) ResetStatistics ¶
func (c *Cache) ResetStatistics()
ResetStatistics resets all statistics counters (hit rate, evictions, etc.)