Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The request method was POST and an Expiration header was not supplied.
	ReasonRequestMethodPOST = cacheobject.ReasonRequestMethodPOST

	// The request method was PUT and PUTs are not cachable.
	ReasonRequestMethodPUT = cacheobject.ReasonRequestMethodPUT

	// The request method was DELETE and DELETEs are not cachable.
	ReasonRequestMethodDELETE = cacheobject.ReasonRequestMethodDELETE

	// The request method was CONNECT and CONNECTs are not cachable.
	ReasonRequestMethodCONNECT = cacheobject.ReasonRequestMethodCONNECT

	// The request method was OPTIONS and OPTIONS are not cachable.
	ReasonRequestMethodOPTIONS = cacheobject.ReasonRequestMethodOPTIONS

	// The request method was TRACE and TRACEs are not cachable.
	ReasonRequestMethodTRACE = cacheobject.ReasonRequestMethodTRACE

	// The request method was not recognized by cachecontrol, and should not be cached.
	ReasonRequestMethodUnkown = cacheobject.ReasonRequestMethodUnkown

	// The request included an Cache-Control: no-store header
	ReasonRequestNoStore = cacheobject.ReasonRequestNoStore

	// The request included an Authorization header without an explicit Public or Expiration time: http://tools.ietf.org/html/rfc7234#section-3.2
	ReasonRequestAuthorizationHeader = cacheobject.ReasonRequestAuthorizationHeader

	// The response included an Cache-Control: no-store header
	ReasonResponseNoStore = cacheobject.ReasonResponseNoStore

	// The response included an Cache-Control: private header and this is not a Private cache
	ReasonResponsePrivate = cacheobject.ReasonResponsePrivate

	// The response failed to meet at least one of the conditions specified in RFC 7234 section 3: http://tools.ietf.org/html/rfc7234#section-3
	ReasonResponseUncachableByDefault = cacheobject.ReasonResponseUncachableByDefault
)

Variables

View Source
var DefaultCacheStrategy = NewCacheStrategyWithDefault()
View Source
var DefaultIncludeHeaders = []string{"Authorization", "Accept-Encoding", "Host"}

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a LRU cache with the following features - limits on max entries - memory size limit - ttl for entries

func NewCache

func NewCache(name string, maxEntries int, maxSizeMB int, maxAge time.Duration) *Cache

NewCache creates a new cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

func (*Cache) Invalidate

func (c *Cache) Invalidate()

func (*Cache) Len

func (c *Cache) Len() int

Len returns the total number of entries in the cache

func (*Cache) LogEvery

func (c *Cache) LogEvery(d time.Duration)

LogEvery Start a Goroutine, which logs statistics periodically.

func (*Cache) PurgeEntries

func (c *Cache) PurgeEntries(keys []string)

Purge Entries with a specific hash

func (*Cache) PurgeOldEntries

func (c *Cache) PurgeOldEntries()

PurgeOldEntries removes all entries which are out of their ttl

func (*Cache) PurgedKeysAsString

func (c *Cache) PurgedKeysAsString(keys []string) string

func (*Cache) Set

func (c *Cache) Set(key string, label string, sizeBytes int, cacheObject interface{})

func (*Cache) SizeByte

func (c *Cache) SizeByte() int

SizeByte returns the total memory consumption of the cache

type CacheEntry

type CacheEntry struct {
	// contains filtered or unexported fields
}

type CacheStrategy

type CacheStrategy struct {
	// contains filtered or unexported fields
}

func NewCacheStrategy

func NewCacheStrategy(includeHeaders []string, includeCookies []string, ignoreReasons []cacheobject.Reason) *CacheStrategy

func NewCacheStrategyWithDefault

func NewCacheStrategyWithDefault() *CacheStrategy

func (*CacheStrategy) Hash

func (tcs *CacheStrategy) Hash(method string, url string, requestHeader http.Header) string

Hash computes a hash value based on the url, the method and selected header and cookie attributes.

func (*CacheStrategy) HashWithParameters

func (tcs *CacheStrategy) HashWithParameters(method string, url string, requestHeader http.Header, includeHeaders []string, includeCookies []string) string

Hash computes a hash value based on the url, the method and selected header and cookie attributes.

func (*CacheStrategy) IsCacheable

func (tcs *CacheStrategy) IsCacheable(method string, url string, statusCode int, requestHeader http.Header, responseHeader http.Header) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL