Implement namespace optional arg
This commit is contained in:
11
cache.go
11
cache.go
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
@@ -24,8 +25,9 @@ func NewCache(path ...string) (*Cache, error) {
|
||||
return c, err
|
||||
}
|
||||
|
||||
func (c *Cache) Get(key string) ([]byte, error) {
|
||||
v, ok := c.db.Get(key)
|
||||
func (c *Cache) Get(key string, ns ...string) ([]byte, error) {
|
||||
namespace := resolveNamespace(ns)
|
||||
v, ok := c.db.Get(path.Join(namespace, key))
|
||||
if !ok {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
@@ -36,8 +38,9 @@ func (c *Cache) Get(key string) ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (c *Cache) Set(key string, value []byte) error {
|
||||
c.db.Set(key, value, 0)
|
||||
func (c *Cache) Set(key string, value []byte, ns ...string) error {
|
||||
namespace := resolveNamespace(ns)
|
||||
c.db.Set(path.Join(namespace, key), value, 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user