Implement namespace optional arg

This commit is contained in:
Bel LaPointe
2019-03-20 09:54:26 -06:00
parent b79cb97ba6
commit b7a231feaf
10 changed files with 101 additions and 45 deletions

View File

@@ -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
}