Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeReqRes(r io.Reader) (*http.Request, *http.Response, error)
- func EncodeReqRes(req *http.Request, res *http.Response, w io.Writer) error
- func KeyToPath(key string, n int) string
- func Seed(req *http.Request, vary []string) (string, error)
- func SetCacheResultHeader(res *http.Response, hit bool)
- type DiskCache
- func (c *DiskCache) Delete(key string)
- func (c *DiskCache) DeleteExpired()
- func (c *DiskCache) Load(key string) (*http.Request, *http.Response, error)
- func (c *DiskCache) Metrics() Metrics
- func (c *DiskCache) StartAutoCleanup()
- func (c *DiskCache) StopAutoCleanup()
- func (c *DiskCache) Store(key string, req *http.Request, res *http.Response) error
- func (c *DiskCache) StoreWithTTL(key string, req *http.Request, res *http.Response, ttl time.Duration) error
- type DiskCacheOption
- type Metrics
- type WriteCounter
Constants ¶
const ( // NoLimitKeys is a special value that means no limit on the number of keys. NoLimitKeys = 0 // NoLimitTotalBytes is a special value that means no limit on the total number of bytes. NoLimitTotalBytes = 0 // NoLimitTTL is a special value that means no limit on the TTL. NoLimitTTL = ttlcache.NoTTL )
const ( CacheResultHeader = "X-Cache" CacheHit = "HIT" CacheMiss = "MISS" )
Variables ¶
var ErrCacheFull error = errors.New("cache full")
ErrCacheFull is returned if the cache is full
Functions ¶
func DecodeReqRes ¶
DecodeReqRes decodes to http.Request and http.Response.
func EncodeReqRes ¶
EncodeReqRes encodes http.Request and http.Response.
func KeyToPath ¶
KeyToPath converts key to path It is the responsibility of the user to pass path-safe keys
func SetCacheResultHeader ¶
SetCacheResultHeader sets cache header.
Types ¶
type DiskCache ¶
type DiskCache struct {
// contains filtered or unexported fields
}
DiskCache is a disk cache implementation.
func NewDiskCache ¶
func NewDiskCache(cacheRoot string, defaultTTL time.Duration, opts ...DiskCacheOption) (*DiskCache, error)
NewDiskCache returns a new DiskCache. cacheRoot: the root directory of the cache. defaultTTL: the default TTL of the cache. maxKeys: the maximum number of keys that can be stored in the cache. If NoLimitKeys is specified, there is no limit. maxTotalBytes: the maximum number of bytes that can be stored in the cache. If NoLimitTotalBytes is specified, there is no limit.
func (*DiskCache) DeleteExpired ¶
func (c *DiskCache) DeleteExpired()
DeleteExpired deletes expired caches.
func (*DiskCache) StartAutoCleanup ¶
func (c *DiskCache) StartAutoCleanup()
StartAutoCleanup starts the goroutine of automatic cache cleanup
func (*DiskCache) StopAutoCleanup ¶
func (c *DiskCache) StopAutoCleanup()
StopAutoCleanup stops the auto cleanup cache.
type DiskCacheOption ¶
type DiskCacheOption func(*DiskCache)
DiskCacheOption is an option for DiskCache.
func DisableAutoCleanup ¶
func DisableAutoCleanup() DiskCacheOption
DisableAutoCleanup disables the automatic cache cleanup.
func DisableWarmUp ¶
func DisableWarmUp() DiskCacheOption
DisableWarmUp disables the automatic cache warm up.
func EnableTouchOnHit ¶
func EnableTouchOnHit() DiskCacheOption
EnableTouchOnHit enables the touch on hit feature.
func MaxKeys ¶
func MaxKeys(n uint64) DiskCacheOption
MaxKeys sets the maximum number of keys that can be stored in the cache.
func MaxTotalBytes ¶
func MaxTotalBytes(n uint64) DiskCacheOption
MaxTotalBytes sets the maximum number of bytes that can be stored in the cache.