Documentation
¶
Overview ¶
Package memcache provides a simple in-memory cache with per-item TTL, backed by patrickmn/go-cache.
Use DefaultTtl for the cache's default expiration and Forever for items that never expire.
Index ¶
Examples ¶
Constants ¶
View Source
const ( DefaultTtl = 0 Forever = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemCache ¶
type MemCache interface {
// Get retrieves item by key
Get(key string) (interface{}, bool)
// Set sets item with key and ttl
// If the duration is 0, the cache's default expiration time is used.
// If it is -1, the item never expires.
Set(key string, v interface{}, ttl time.Duration)
// Delete deletes key
Delete(key string)
}
MemCache provides in simple memory cache with ttl
Example ¶
package main
import (
"fmt"
"github.com/zloevil/jet/memcache"
)
func main() {
c := memcache.NewMemCache()
c.Set("greeting", "hello", memcache.DefaultTtl)
v, ok := c.Get("greeting")
fmt.Println(v, ok)
_, ok = c.Get("missing")
fmt.Println(ok)
}
Output: hello true false
func NewMemCache ¶
func NewMemCache() MemCache
Click to show internal directories.
Click to hide internal directories.