Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeReq(r io.Reader) (*http.Request, error)
- func DecodeReqRes(r io.Reader) (*http.Request, *http.Response, error)
- func DecodeRes(r io.Reader) (*http.Response, error)
- func EncodeReq(req *http.Request, w io.Writer) error
- func EncodeReqRes(req *http.Request, res *http.Response, w io.Writer) error
- func EncodeRes(res *http.Response, w io.Writer) error
- func KeyToPath(key string, n int) string
- func PathToKey(path string) 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, err error)
- func (c *DiskCache) Metrics() Metrics
- func (c *DiskCache) StartAutoCleanup()
- func (c *DiskCache) StopAdjust()
- func (c *DiskCache) StopAll()
- func (c *DiskCache) StopAutoCleanup()
- func (c *DiskCache) StopWarmUp()
- 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) (err error)
- type DiskCacheOption
- func DisableAutoCleanup() DiskCacheOption
- func DisableWarmUp() DiskCacheOption
- func EnableAutoAdjust() DiskCacheOption
- func EnableAutoAdjustWithPercentage(percentage uint64) DiskCacheOption
- func EnableTouchOnHit() DiskCacheOption
- func MaxKeys(n uint64) DiskCacheOption
- func MaxTotalBytes(n uint64) 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 // DefaultCacheDirLen is the default length of the cache directory name. DefaultCacheDirLen = 2 )
const ( CacheResultHeader = "X-Cache" CacheHit = "HIT" CacheMiss = "MISS" )
Variables ¶
var ErrCacheFull error = errors.New("cache full")
ErrCacheFull is returned if the cache is full
var ErrInvalidRequest = errors.New("invalid request")
var ErrNoRequest = errors.New("no request")
Functions ¶
func DecodeReqRes ¶
DecodeReqRes decodes to http.Request and http.Response. Depracated: Use DecodeReq and DecodeRes instead.
func EncodeReqRes ¶
EncodeReqRes encodes http.Request and http.Response. Depracated: Use EncodeReq and EncodeRes instead.
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) StopAll ¶ added in v0.14.0
func (c *DiskCache) StopAll()
StopAll stops all the goroutines of the cache.
func (*DiskCache) StopAutoCleanup ¶
func (c *DiskCache) StopAutoCleanup()
StopAutoCleanup stops the auto cleanup cache.
func (*DiskCache) StopWarmUp ¶ added in v0.14.0
func (c *DiskCache) StopWarmUp()
StopWarmUp stops the warm up cache.
type DiskCacheOption ¶
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 EnableAutoAdjust ¶ added in v0.12.0
func EnableAutoAdjust() DiskCacheOption
EnableAutoAdjust enables auto-adjustment to delete the oldest cache when the total cache size limit (maxTotalBytes) is reached.
func EnableAutoAdjustWithPercentage ¶ added in v0.13.0
func EnableAutoAdjustWithPercentage(percentage uint64) DiskCacheOption
EnableAutoAdjustWithPercentage enables auto-adjustment to delete the oldest cache when the total cache size limit (maxTotalBytes) is reached. percentage: Delete until what percentage of the total byte size is reached.
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.