Documentation ¶
Overview ¶
Package cache provides a simple in-memory key:value cache
Index ¶
Examples ¶
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 cache instance
func New ¶
New creates new cache instance
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") fmt.Println(cache.Get("test"))
Output: ABCD
func (*Cache) Delete ¶
Delete removes item from cache
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") cache.Delete("test") fmt.Println(cache.Get("test"))
Output: <nil>
func (*Cache) Expired ¶
Expired returns number of expired items in cache
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") fmt.Println(cache.Expired())
Output: 0
func (*Cache) Flush ¶
func (s *Cache) Flush()
Flush removes all data from cache
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") cache.Flush() fmt.Println(cache.Get("test"))
Output: <nil>
func (*Cache) Get ¶
Get returns item from cache or nil
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") fmt.Println(cache.Get("test"))
Output: ABCD
func (*Cache) GetWithExpiration ¶
GetWithExpiration returns item from cache and expiration date or nil
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") item, exp := cache.GetWithExpiration("test") fmt.Println(item, exp.String())
Output:
func (*Cache) Has ¶
Has returns true if cache contains data for given key
Example ¶
cache := New(time.Second, time.Minute) cache.Set("test", "ABCD") fmt.Println(cache.Has("test"))
Output: true
Click to show internal directories.
Click to hide internal directories.