Documentation ¶
Index ¶
- Constants
- func StartTicks(tickInterval time.Duration)
- func Tick()
- type Cache
- func (c *Cache) Add(key, value interface{}) (evicted bool)
- func (c *Cache) Clear()
- func (c *Cache) Contains(key interface{}) bool
- func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool)
- func (c *Cache) Get(key interface{}) (value interface{}, ok bool)
- func (c *Cache) GetOldest() (key interface{}, value interface{}, ok bool)
- func (c *Cache) Keys() []interface{}
- func (c *Cache) Len() int
- func (c *Cache) Peek(key interface{}) (value interface{}, ok bool)
- func (c *Cache) PeekOrAdd(key, value interface{}) (previous interface{}, ok, evicted bool)
- func (c *Cache) Remove(key interface{}) (present bool)
- func (c *Cache) RemoveOldest() (key interface{}, value interface{}, ok bool)
- func (c *Cache) Resize(size int) (evicted int)
- type CacheInfo
- type CacheWithTTL
- func (t *CacheWithTTL) Add(key, value interface{}) bool
- func (t *CacheWithTTL) Clear()
- func (t *CacheWithTTL) Contains(key interface{}) bool
- func (t *CacheWithTTL) Dispose()
- func (t *CacheWithTTL) Get(key interface{}) (value interface{}, ok bool)
- func (t *CacheWithTTL) Keys() []interface{}
- func (t *CacheWithTTL) Len() int
- func (t *CacheWithTTL) Peek(key interface{}) (value interface{}, ok bool)
- func (t *CacheWithTTL) Remove(key interface{}) bool
- func (t *CacheWithTTL) RemoveOldest() (key interface{}, value interface{}, ok bool)
- type CallbackFunc
- type ConnectivityCache
- type ConnectivityTester
- type EvictionCallback
- type LRU
- func (c *LRU) Add(key, value interface{}) bool
- func (c *LRU) Clear()
- func (c *LRU) Contains(key interface{}) (ok bool)
- func (c *LRU) Get(key interface{}) (value interface{}, ok bool)
- func (c *LRU) GetOldest() (key interface{}, value interface{}, ok bool)
- func (c *LRU) Keys() []interface{}
- func (c *LRU) Len() int
- func (c *LRU) Peek(key interface{}) (value interface{}, ok bool)
- func (c *LRU) Remove(key interface{}) (present bool)
- func (c *LRU) RemoveOldest() (key, value interface{}, ok bool)
- func (c *LRU) Resize(newSize int) int
- type LRUCache
- type Timer
Constants ¶
const (
MIN_TIMER_INTERVAL = 1 * time.Millisecond
)
Variables ¶
This section is empty.
Functions ¶
func StartTicks ¶
Start the self-ticking routine, which ticks per tickInterval
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe fixed size LRU cache.
func NewThreadSafeCache ¶
New creates an LRU of the given size.
func NewThreadSafeWithEvict ¶
func NewThreadSafeWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*Cache, error)
NewWithEvict constructs a fixed size cache with the given eviction callback.
func (*Cache) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*Cache) ContainsOrAdd ¶
ContainsOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.
func (*Cache) Keys ¶
func (c *Cache) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*Cache) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*Cache) PeekOrAdd ¶
PeekOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.
func (*Cache) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
type CacheWithTTL ¶
func (*CacheWithTTL) Add ¶
func (t *CacheWithTTL) Add(key, value interface{}) bool
Add adds the item to the cache. It also includes the `lastAccessTime` to the value. Life of an item can be increased by calling `Add` multiple times on the same key.
func (*CacheWithTTL) Clear ¶
func (t *CacheWithTTL) Clear()
Purge is used to completely clear the cache.
func (*CacheWithTTL) Contains ¶
func (t *CacheWithTTL) Contains(key interface{}) bool
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*CacheWithTTL) Dispose ¶
func (t *CacheWithTTL) Dispose()
func (*CacheWithTTL) Get ¶
func (t *CacheWithTTL) Get(key interface{}) (value interface{}, ok bool)
Get looks up a key's value from the cache. Also, it unmarshals `lastAccessTime` from `Get` response
func (*CacheWithTTL) Keys ¶
func (t *CacheWithTTL) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*CacheWithTTL) Len ¶
func (t *CacheWithTTL) Len() int
Len returns the number of items in the cache.
func (*CacheWithTTL) Peek ¶
func (t *CacheWithTTL) Peek(key interface{}) (value interface{}, ok bool)
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key. Also, it unmarshals the `lastAccessTime` from the result
func (*CacheWithTTL) Remove ¶
func (t *CacheWithTTL) Remove(key interface{}) bool
Remove removes the provided key from the cache.
func (*CacheWithTTL) RemoveOldest ¶
func (t *CacheWithTTL) RemoveOldest() (key interface{}, value interface{}, ok bool)
RemoveOldest removes the oldest item from the cache.
type ConnectivityCache ¶
type ConnectivityCache struct {
// contains filtered or unexported fields
}
func NewConnectivityCache ¶
func NewConnectivityCache() (*ConnectivityCache, error)
func (*ConnectivityCache) ClearBrowser ¶
func (c *ConnectivityCache) ClearBrowser()
func (*ConnectivityCache) IsOk ¶
func (c *ConnectivityCache) IsOk(url string) bool
func (*ConnectivityCache) IsOkAndSet ¶
func (c *ConnectivityCache) IsOkAndSet(u string, f func() bool) bool
IsOkAndSet checks if the `u` value is contained, if it's not it checks it. This operation is thread safe, you can use it to modify the cache state in the function.
func (*ConnectivityCache) SetBrowser ¶
func (c *ConnectivityCache) SetBrowser(bow *browser.Browser)
func (*ConnectivityCache) Test ¶
func (c *ConnectivityCache) Test(u string) error
type ConnectivityTester ¶ added in v0.2.2
type ConnectivityTester interface { //IsOkAndSet checks if the `u` value is contained, if it's not it checks it. //This operation should be thread safe, you can use it to modify the cache state in the function. IsOkAndSet(u string, f func() bool) bool //Test if the operation can be completed with success. If so, cache that. Test(u string) error SetBrowser(bow *browser.Browser) ClearBrowser() }
type EvictionCallback ¶
type EvictionCallback func(key interface{}, value interface{})
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU is a non-thread safe fixed size LRU cache
func NewLRU ¶
func NewLRU(size int, onEviction EvictionCallback) (*LRU, error)
NewLRU creates a new LRU of the given size
func (*LRU) Add ¶
Add a key with a given value returns true if an element was evicted so this one could be added
func (*LRU) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*LRU) Get ¶
Get looks up a key's value from the cache. this updates the recent-ness of the cache
func (*LRU) Peek ¶
Peek returns the key value (or nil if not found) without updating the "recently used"-ness of the key.
func (*LRU) Remove ¶
Remove removes the provided key from the cache, returning if the key was contained.
func (*LRU) RemoveOldest ¶
RemoveOldest removes the oldest item in the cache
type LRUCache ¶
type LRUCache interface { // Adds a value to the cache, returns true if an eviction occurred and // updates the "recently used"-ness of the key. Add(key, value interface{}) bool // Returns key's value from the cache and // updates the "recently used"-ness of the key. #value, isFound Get(key interface{}) (value interface{}, ok bool) // Checks if a key exists in cache without updating the recent-ness. Contains(key interface{}) (ok bool) // Returns key's value without updating the "recently used"-ness of the key. Peek(key interface{}) (value interface{}, ok bool) // Removes a key from the cache. Remove(key interface{}) bool // Removes the oldest entry from cache. RemoveOldest() (interface{}, interface{}, bool) // Returns the oldest entry from the cache. #key, value, isFound GetOldest() (interface{}, interface{}, bool) // Returns a slice of the keys in the cache, from oldest to newest. Keys() []interface{} // Returns the number of items in the cache. Len() int // Clears all cache entries. Clear() // Resizes cache, returning number evicted Resize(int) int }
LRUCache is the interface for simple LRU cache.
func NewTTLWithEvict ¶
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
func AddCallback ¶
func AddCallback(d time.Duration, callback CallbackFunc) *Timer
Add a callback which will be called after specified duration