2015-10-20 23:45:24 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/koding/cache"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Cache interface {
|
|
|
|
Get(string) (interface{}, error)
|
|
|
|
Set(string, interface{}) error
|
|
|
|
}
|
|
|
|
|
|
|
|
func Get(c context.Context, key string) (interface{}, error) {
|
|
|
|
return FromContext(c).Get(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Set(c context.Context, key string, value interface{}) error {
|
|
|
|
return FromContext(c).Set(key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default creates an in-memory cache with the default
|
2016-01-21 21:23:19 +00:00
|
|
|
// 30 minute expiration period.
|
2015-10-20 23:45:24 +00:00
|
|
|
func Default() Cache {
|
2016-01-21 21:23:19 +00:00
|
|
|
return cache.NewMemoryWithTTL(time.Minute * 30)
|
2015-10-20 23:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTTL returns an in-memory cache with the specified
|
|
|
|
// ttl expiration period.
|
|
|
|
func NewTTL(t time.Duration) Cache {
|
|
|
|
return cache.NewMemoryWithTTL(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTTL returns an in-memory cache with the specified
|
|
|
|
// ttl expiration period.
|
|
|
|
func NewLRU(size int) Cache {
|
|
|
|
return cache.NewLRU(size)
|
|
|
|
}
|