Documentation
¶
Index ¶
- Constants
- type CacheDriver
- func (cache *CacheDriver) Capacity() int
- func (cache *CacheDriver) Clean() error
- func (cache *CacheDriver) Contains(keyVal interface{}) (bool, error)
- func (cache *CacheDriver) ExtendedCapacity() int
- func (cache *CacheDriver) GetState() (string, error)
- func (cache *CacheDriver) HitCount() int
- func (cache *CacheDriver) LazyRemove(keyVal interface{}) error
- func (cache *CacheDriver) MissCount() int
- func (cache *CacheDriver) NewCacheIt() *CacheIt
- func (cache *CacheDriver) NumEntries() int
- func (cache *CacheDriver) RetrieveFromCacheOrCompute(request interface{}, other ...interface{}) (interface{}, *RequestError)
- func (cache *CacheDriver) Set(capacity int, ttl time.Duration) error
- func (cache *CacheDriver) Touch(keyVal interface{}) error
- func (cache *CacheDriver) Ttl() time.Duration
- type CacheEntry
- type CacheIt
- type CacheState
- type RequestError
Constants ¶
const ( AVAILABLE = iota COMPUTING COMPUTED FAILED5xx FAILED4xx FAILED5XXMISSHANDLERERROR )
State that a cache entry could have
const ( Status4xx = iota Status4xxCached Status5xx Status5xxCached StatusUser )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheDriver ¶
type CacheDriver struct {
// contains filtered or unexported fields
}
func New ¶
func New(capacity int, capFactor float64, ttl time.Duration, toMapKey func(key interface{}) (string, error), preProcessRequest func(request interface{}, other ...interface{}) (interface{}, *RequestError), callUServices func(request, payload interface{}, other ...interface{}) (interface{}, *RequestError), ) *CacheDriver
New Creates a new cache. Parameters are:
capacity: maximum number of entries that cache can manage without evicting the least recently used
capFactor is a number in (0.1, 3] that indicates how long the cache should be oversize in order to avoid rehashing
ttl: time to live of a cache entry
toMapKey is a function in charge of transforming the request into a string
preProcessRequest is an optional function that could be used for validation, transforming the request in a more suitable form, etc.
callUService: is responsible for calling to the service and building a byte sequence corresponding to the service response
func NewWithCompression ¶ added in v1.2.3
func NewWithCompression(capacity int, capFactor float64, ttl time.Duration, toMapKey func(key interface{}) (string, error), valueToBytes func(value interface{}) ([]byte, error), bytesToValue func([]byte) (interface{}, error), preProcessRequest func(request interface{}, other ...interface{}) (interface{}, *RequestError), callUServices func(request, payload interface{}, other ...interface{}) (interface{}, *RequestError), ) (cache *CacheDriver)
NewWithCompression Creates a new cache with compressed entries.
The constructor is some similar to the version that does not compress. The difference is that in order to compress, the cache needs a serialized representation of what will be stored into the cache. For that reason, the constructor receives two additional functions. The first function, ValueToBytes transforms the value into a byte slice (type []byte). The second function, bytesToValue, takes a serialized representation of the value stored into the cache, and it transforms it to the original representation.
Parameters are:
capacity: maximum number of entries that cache can manage without evicting the least recently used
capFactor is a number in (0.1, 3] that indicates how long the cache should be oversize in order to avoid rehashing
ttl: time to live of a cache entry
toMapKey is a function in charge of transforming the request into a string
valueToBytes transforms the value into a []byte
bytesToValue transforms a []byte into the original value representation
valueToBytes
preProcessRequest is an optional function that could be used for validation, transforming the request in a more suitable form, etc.
callUService: is responsible for calling to the service and building a byte sequence corresponding to the service response
func (*CacheDriver) Capacity ¶ added in v1.2.1
func (cache *CacheDriver) Capacity() int
func (*CacheDriver) Clean ¶
func (cache *CacheDriver) Clean() error
Clean Try to clean the cache. All the entries are deleted and counters reset. Fails if any entry is in COMPUTING state.
Uses internal lock
func (*CacheDriver) Contains ¶ added in v1.2.7
func (cache *CacheDriver) Contains(keyVal interface{}) (bool, error)
Contains returns true if the cache contains keyVal. It does not update the entry timestamp and consequently it does not change the eviction order.
func (*CacheDriver) ExtendedCapacity ¶ added in v1.2.1
func (cache *CacheDriver) ExtendedCapacity() int
func (*CacheDriver) GetState ¶
func (cache *CacheDriver) GetState() (string, error)
GetState Return a json containing the cache state. Use the internal mutex. Be careful with a deadlock
func (*CacheDriver) HitCount ¶ added in v1.2.1
func (cache *CacheDriver) HitCount() int
func (*CacheDriver) LazyRemove ¶ added in v1.2.7
func (cache *CacheDriver) LazyRemove(keyVal interface{}) error
LazyRemove removes the entry with keyVal from the cache. It does not remove the entry immediately, but it marks it as removed.
func (*CacheDriver) MissCount ¶ added in v1.2.1
func (cache *CacheDriver) MissCount() int
func (*CacheDriver) NewCacheIt ¶
func (cache *CacheDriver) NewCacheIt() *CacheIt
func (*CacheDriver) NumEntries ¶ added in v1.2.1
func (cache *CacheDriver) NumEntries() int
func (*CacheDriver) RetrieveFromCacheOrCompute ¶
func (cache *CacheDriver) RetrieveFromCacheOrCompute(request interface{}, other ...interface{}) (interface{}, *RequestError)
RetrieveFromCacheOrCompute Search Request in the cache. If the request is already computed, then it immediately returns the cached entry. If the request is the first, then it blocks until the result is ready. If the request is not the first but the result is not still ready, then it blocks until the result is ready
func (*CacheDriver) Touch ¶ added in v1.2.7
func (cache *CacheDriver) Touch(keyVal interface{}) error
func (*CacheDriver) Ttl ¶ added in v1.2.1
func (cache *CacheDriver) Ttl() time.Duration
type CacheEntry ¶
type CacheEntry struct {
// contains filtered or unexported fields
}
CacheEntry Every cache entry has this information
type CacheIt ¶
type CacheIt struct {
// contains filtered or unexported fields
}
CacheIt Iterator on cache entries. Go from MUR to LRU
func (*CacheIt) GetCurr ¶
func (it *CacheIt) GetCurr() *CacheEntry
func (*CacheIt) Next ¶
func (it *CacheIt) Next() *CacheEntry