Documentation
¶
Index ¶
- type Cache
- func (c *Cache) Cap() int
- func (c *Cache) Contains(key interface{}) (ok bool)
- func (c *Cache) DelSilently(key interface{})
- func (c *Cache) Delete(key interface{})
- func (c *Cache) Discard() (key, value interface{})
- func (c *Cache) Expiry(key interface{}) (t time.Time, ok bool)
- func (c *Cache) GC() time.Duration
- func (c *Cache) Ignore(ch chan<- Event, ops ...Op)
- func (c *Cache) Keys() (keys []interface{})
- func (c *Cache) Len() int
- func (c *Cache) Load(key interface{}) (interface{}, bool)
- func (c *Cache) Notify(ch chan<- Event, ops ...Op)
- func (c *Cache) Peek(key interface{}) (interface{}, bool)
- func (c *Cache) Purge()
- func (c *Cache) RegisterOnEvicted(fn func(key, value interface{}))
- func (c *Cache) RegisterOnExpired(fn func(key, value interface{}))
- func (c *Cache) Resize(size int) int
- func (c *Cache) SetTTL(ttl time.Duration)
- func (c *Cache) Store(key, value interface{})
- func (c *Cache) StoreWithTTL(key, value interface{}, ttl time.Duration)
- func (c *Cache) TTL() time.Duration
- func (c *Cache) Update(key, value interface{})
- type Collection
- type Entry
- type Event
- type Op
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is an abstracted cache that provides a skeletal implementation, of the Cache interface to minimize the effort required to implement interface.
func (*Cache) DelSilently ¶
func (c *Cache) DelSilently(key interface{})
DelSilently the key value silently without call onEvicted.
func (*Cache) Discard ¶
func (c *Cache) Discard() (key, value interface{})
Discard oldest entry from cache to make room for the new ones.
func (*Cache) GC ¶ added in v1.0.5
GC returns the remaining time duration for the next gc cycle if there any, Otherwise, it return 0.
Calling GC without waits for the duration to elapsed considered a no-op.
func (*Cache) Ignore ¶ added in v1.0.5
Ignore causes the provided ops to be ignored. Ignore undoes the effect of any prior calls to Notify for the provided ops. If no ops are provided, ch removed.
func (*Cache) Notify ¶ added in v1.0.5
Notify causes cache to relay events to ch. If no operations are provided, all incoming operations will be relayed to ch. Otherwise, just the provided operations will.
func (*Cache) RegisterOnEvicted ¶
func (c *Cache) RegisterOnEvicted(fn func(key, value interface{}))
RegisterOnEvicted registers a function, to call it when an entry is purged from the cache.
func (*Cache) RegisterOnExpired ¶
func (c *Cache) RegisterOnExpired(fn func(key, value interface{}))
RegisterOnExpired registers a function, to call it when an entry TTL elapsed.
func (*Cache) StoreWithTTL ¶
StoreWithTTL sets the key value with TTL overrides the default.
type Collection ¶
type Collection interface { Move(*Entry) Add(*Entry) Remove(*Entry) Discard() *Entry Len() int Init() }
Collection represents the cache underlying data structure, and defines the functions or operations that can be applied to the data elements.
type Entry ¶
type Entry struct { Key interface{} Value interface{} Element interface{} Exp time.Time // contains filtered or unexported fields }
Entry is used to hold a value in the cache.
type Event ¶ added in v1.0.5
type Event struct { // Op represents cache operation that triggered the event. Op Op // Key represents cache entry key. Key interface{} // Value represents cache key value. Value interface{} // Expiry represents cache key value expiry time. Expiry time.Time // Ok report whether the read operation succeed. Ok bool }
Event represents a single cache entry change.