Documentation ¶
Overview ¶
Package safestore provides a possibly threadsafe key-value cache.
Index ¶
- type I
- type Item
- type T
- func (rq *T) Get(key interface{}) (v interface{})
- func (rq *T) GetAll() (v [][2]interface{})
- func (rq *T) Gets(key ...interface{}) (v []interface{})
- func (rq *T) Gets2(items ...*Item)
- func (rq *T) Incr(key interface{}, delta int64, initVal uint64) (newval uint64)
- func (rq *T) Put(key interface{}, val interface{}, ttl time.Duration)
- func (rq *T) Puts(items ...*Item)
- func (rq *T) Removes(key ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type I ¶
type I interface { Put(key interface{}, val interface{}, ttl time.Duration) Puts(items ...*Item) Removes(keys ...interface{}) Get(key interface{}) interface{} Gets(keys ...interface{}) (v []interface{}) }
I is an interface for a map with expiry support.
type T ¶
type T struct {
// contains filtered or unexported fields
}
The T can be used as a thread-safe map of anything to anything. Use it as a request-scoped cache, etc
Sample Uses:
- Long-lived shared Cache store
- Short-lived Request-Scoped Attribute Store ...
A T can be lock enabled or not. If you do not use any goroutines within your code, then create a lock-less T. Purging within a lock-less T is best effort (we don't synchronize anything).
We also support using safestore as a cache.
- You put in items along with a timestamp and expiry time
- A goroutine runs which will purge expired entries out of the cache
Note that, even when used as a cache with a TTL, Get will always return the actual value stored.
Click to show internal directories.
Click to hide internal directories.