Documentation ¶
Index ¶
- type Config
- type Cursor
- func (c *Cursor) Delete() Cursor
- func (c *Cursor) Get(k interface{}) Cursor
- func (c *Cursor) IsExpired(now time.Time) bool
- func (c *Cursor) IsNil() bool
- func (c *Cursor) KeyValue() (k, v interface{})
- func (c *Cursor) MoveToFront(t time.Time) Cursor
- func (c *Cursor) Next() Cursor
- func (c *Cursor) Prev() Cursor
- func (c *Cursor) Set(v interface{})
- type ExpireQueue
- func (q *ExpireQueue) Back() Cursor
- func (q *ExpireQueue) CleanN(n int)
- func (q *ExpireQueue) Count() int
- func (q *ExpireQueue) Delete(k interface{})
- func (q *ExpireQueue) Front() Cursor
- func (q *ExpireQueue) Get(k interface{}) (interface{}, bool)
- func (q *ExpireQueue) IsFull() bool
- func (q *ExpireQueue) NewCursor(k interface{}) Cursor
- func (q *ExpireQueue) Push(k, v interface{}, t time.Time, c *Cursor)
- func (q *ExpireQueue) Set(k, v interface{})
- func (q *ExpireQueue) SetTTL(ttl time.Duration)
- type TimeChanSource
- type TimeDeferSource
- type TimeNativeSource
- type TimeSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v1.2.0
type Config struct { // TTL specifies the TTL of an item in the queue. While performing // Set operation the TTL will be checked for items in the bottom // of the queue. CleanN operation also relies on this setting. If // zero, no limit will be imposed on the queue. TTL time.Duration // MaxItems specifies max number of keys to store in the queue. If // there is more than MaxItems in a queue, Set operation will // expire the item in the bottom of the queue. If zero, no limit // will be imposed on the queue. CleanN also respects this // setting. MaxItems int // BackScan specifies maximum items will be scanned from bottom // to the top until non-expiring item will be met. All items found // are to be removed as expired on Set operation. Zero value is // the same as 1. BackScan int }
Config describes various settings of the ExpireQueue.
type Cursor ¶ added in v1.2.0
type Cursor struct {
// contains filtered or unexported fields
}
Cursor points to specific element of the queue.
func (*Cursor) Delete ¶ added in v1.2.0
Delete removes current key/value and returns a cursor right after given one of Nil element if it doesn't exist.
func (*Cursor) IsExpired ¶ added in v1.2.0
IsExpired tells if the cursor has expired key-value relative to given timestamp.
func (*Cursor) IsNil ¶ added in v1.2.0
IsNil tells if the cursor is a Nil element, i.e. not related to actual key/value in the queue.
func (*Cursor) KeyValue ¶ added in v1.2.0
func (c *Cursor) KeyValue() (k, v interface{})
KeyValue returns key-value pair under the cursor.
func (*Cursor) MoveToFront ¶ added in v1.2.0
MoveToFront updates timestamp in cursor to specified value and moves it up front.
type ExpireQueue ¶
type ExpireQueue struct {
// contains filtered or unexported fields
}
ExpireQueue implements basic Get/Set map operations in a form of a priority queue.
func New ¶
func New(ttl time.Duration) *ExpireQueue
New is a shortcut for NewWithOpts with BackScan set to 1 and MaxItems set to 0.
func NewWithOpts ¶ added in v1.2.0
func NewWithOpts(c *Config) *ExpireQueue
NewWithOpts return new instance of ExpireQueue with specified options.
func (*ExpireQueue) Back ¶ added in v1.2.0
func (q *ExpireQueue) Back() Cursor
Back returns rear element of the queue.
func (*ExpireQueue) CleanN ¶
func (q *ExpireQueue) CleanN(n int)
CleanN tries to pop up to n tail elements if they're expired.
func (*ExpireQueue) Count ¶
func (q *ExpireQueue) Count() int
Count returns number of elements in the queue.
func (*ExpireQueue) Delete ¶ added in v1.2.0
func (q *ExpireQueue) Delete(k interface{})
Delete removes key and value.
func (*ExpireQueue) Front ¶ added in v1.2.0
func (q *ExpireQueue) Front() Cursor
Front returns front element of the queue.
func (*ExpireQueue) Get ¶
func (q *ExpireQueue) Get(k interface{}) (interface{}, bool)
Get retrives value by key.
func (*ExpireQueue) IsFull ¶ added in v1.2.0
func (q *ExpireQueue) IsFull() bool
IsFull tells if the queue if full, i.e. its length is at the max.
func (*ExpireQueue) NewCursor ¶ added in v1.2.0
func (q *ExpireQueue) NewCursor(k interface{}) Cursor
NewCursor creates a cursor at the specified key. If corresponding element doesn't exist return Nil element.
func (*ExpireQueue) Push ¶ added in v1.2.0
func (q *ExpireQueue) Push(k, v interface{}, t time.Time, c *Cursor)
Push inserts new element at the top of the queue with given key/value pair, timestamp and a cursor from this queue which may be substituted. The reusing of the cursor relieves pressure on GC.
func (*ExpireQueue) Set ¶
func (q *ExpireQueue) Set(k, v interface{})
Set sets key and value in a queue.
func (*ExpireQueue) SetTTL ¶ added in v1.2.0
func (q *ExpireQueue) SetTTL(ttl time.Duration)
SetTTL specifies new TTL for entries.
type TimeChanSource ¶ added in v1.2.0
type TimeChanSource struct {
// contains filtered or unexported fields
}
func NewTimeChanSource ¶ added in v1.2.0
func NewTimeChanSource(res time.Duration) *TimeChanSource
func (*TimeChanSource) Now ¶ added in v1.2.0
func (ts *TimeChanSource) Now() time.Time
type TimeDeferSource ¶ added in v1.2.0
type TimeDeferSource struct { N int // contains filtered or unexported fields }
func (*TimeDeferSource) Now ¶ added in v1.2.0
func (ts *TimeDeferSource) Now() time.Time
type TimeNativeSource ¶ added in v1.2.0
type TimeNativeSource struct{}
func (*TimeNativeSource) Now ¶ added in v1.2.0
func (ts *TimeNativeSource) Now() time.Time