Documentation ¶
Index ¶
- Variables
- type Cache
- type Entry
- type FIFO
- type Item
- type LRU
- type PriorityQueue
- func (pq *PriorityQueue) Elems() []*Entry
- func (pq *PriorityQueue) Get(id uint64) *Entry
- func (pq *PriorityQueue) Len() int
- func (pq *PriorityQueue) Peek() *Entry
- func (pq *PriorityQueue) Put(priority int, value PriorityQueueItem) bool
- func (pq *PriorityQueue) Remove(id uint64)
- func (pq *PriorityQueue) Tail() *Entry
- type PriorityQueueItem
- type TTLString
- func (c TTLString) Clear()
- func (c *TTLString) Get(id string) (interface{}, bool)
- func (c *TTLString) GetAllID() []string
- func (c TTLString) Len() int
- func (c *TTLString) Pop() (string, interface{}, bool)
- func (c *TTLString) Put(key string, value interface{})
- func (c *TTLString) PutWithTTL(key string, value interface{}, ttl time.Duration)
- func (c TTLString) UpdateTTL(duration time.Duration)
- type TTLUint64
- func (c TTLUint64) Clear()
- func (c *TTLUint64) Exists(id uint64) bool
- func (c *TTLUint64) Get(id uint64) (interface{}, bool)
- func (c *TTLUint64) GetAllID() []uint64
- func (c TTLUint64) Len() int
- func (c *TTLUint64) Put(id uint64, value interface{})
- func (c *TTLUint64) PutWithTTL(key uint64, value interface{}, ttl time.Duration)
- func (c *TTLUint64) Remove(key uint64)
- func (c TTLUint64) UpdateTTL(duration time.Duration)
- type TwoQueue
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCacheType set default cache type for NewDefaultCache function DefaultCacheType = LRUCache )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Put puts an item into cache. Put(key uint64, value interface{}) // Get retrieves an item from cache. Get(key uint64) (interface{}, bool) // Peek reads an item from cache. The action is no considered 'Use'. Peek(key uint64) (interface{}, bool) // Remove eliminates an item from cache. Remove(key uint64) // Elems return all items in cache. Elems() []*Item // Len returns current cache size Len() int }
Cache is an interface for cache system
func NewDefaultCache ¶
NewDefaultCache create Cache instance by default cache type
type Entry ¶
type Entry struct { Priority int Value PriorityQueueItem }
Entry a pair of region and it's priority
type FIFO ¶
FIFO is 'First-In-First-Out' cache.
func (*FIFO) FromLastSameElems ¶
FromLastSameElems returns continuous items that have the same comparable attribute with the the lastest one.
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU is 'Least-Recently-Used' cache.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue queue has priority and preempt
func NewPriorityQueue ¶
func NewPriorityQueue(capacity int) *PriorityQueue
NewPriorityQueue construct of priority queue
func (*PriorityQueue) Elems ¶
func (pq *PriorityQueue) Elems() []*Entry
Elems return all elements in queue
func (*PriorityQueue) Get ¶
func (pq *PriorityQueue) Get(id uint64) *Entry
Get find entry by id from queue
func (*PriorityQueue) Peek ¶
func (pq *PriorityQueue) Peek() *Entry
Peek return the highest priority entry
func (*PriorityQueue) Put ¶
func (pq *PriorityQueue) Put(priority int, value PriorityQueueItem) bool
Put put value with priority into queue
func (*PriorityQueue) Remove ¶
func (pq *PriorityQueue) Remove(id uint64)
Remove remove value from queue
func (*PriorityQueue) Tail ¶
func (pq *PriorityQueue) Tail() *Entry
Tail return the lowest priority entry
type PriorityQueueItem ¶
type PriorityQueueItem interface {
ID() uint64
}
PriorityQueueItem avoid convert cost
type TTLString ¶
type TTLString struct {
// contains filtered or unexported fields
}
TTLString is simple TTL saves key string and value.
func NewStringTTL ¶
NewStringTTL creates a new TTLString cache.
func (*TTLString) PutWithTTL ¶
PutWithTTL puts an item into cache with specified TTL.
type TTLUint64 ¶
type TTLUint64 struct {
// contains filtered or unexported fields
}
TTLUint64 is simple TTL saves only uint64s.
func (*TTLUint64) PutWithTTL ¶
PutWithTTL puts an item into cache with specified TTL.
type TwoQueue ¶
type TwoQueue struct {
// contains filtered or unexported fields
}
TwoQueue is a fixed size 2Q cache. 2Q is an enhancement over the standard LRU cache in that it tracks both frequently and recently used entries separately. This avoids a burst in access to new entries from evicting frequently used entries. It adds some additional tracking overhead to the standard LRU cache, and is computationally about 2x the cost, and adds some metadata over head. The ARCCache is similar, but does not require setting any parameters. TwoQueue implementation is based on https://github.com/hashicorp/golang-lru/blob/master/2q.go