diff --git a/internal/bcache/cache.go b/internal/bcache/cache.go index 957b6c7..85b8cce 100644 --- a/internal/bcache/cache.go +++ b/internal/bcache/cache.go @@ -43,12 +43,14 @@ func (c *Cache) Set(key string, value interface{}, expiration time.Duration) { c.mu.Lock() // TODO: remove debug - fmt.Println(prefix, - termenv.String("<-").Foreground(common.Profile().Color("#DBAB79")), - "Set", - termenv.String(key).Foreground(common.Profile().Color("#A8CC8C")), - termenv.String("=").Foreground(common.Profile().Color("#DBAB79")), - value) + if b, o := value.([]byte); o { + fmt.Println(prefix, + termenv.String("<-").Foreground(common.Profile().Color("#DBAB79")), + "Set", + termenv.String(key).Foreground(common.Profile().Color("#A8CC8C")), + termenv.String("=").Foreground(common.Profile().Color("#DBAB79")), + common.PrettyLimit(string(b), 48)) + } c.values[key] = &node{ expires: c.expiration(expiration), @@ -62,13 +64,14 @@ func (c *Cache) Get(key string) (interface{}, bool) { if v, o := c.values[key]; o && v != nil { if !v.expires.IsExpired() { - // TODO: remove debug - fmt.Println(prefix, - termenv.String("->").Foreground(common.Profile().Color("#66C2CD")), - "Get", - termenv.String(key).Foreground(common.Profile().Color("#A8CC8C")), - termenv.String("=").Foreground(common.Profile().Color("#DBAB79")), - v.value) + if b, o := v.value.([]byte); o { + fmt.Println(prefix, + termenv.String("->").Foreground(common.Profile().Color("#66C2CD")), + "Get", + termenv.String(key).Foreground(common.Profile().Color("#A8CC8C")), + termenv.String("=").Foreground(common.Profile().Color("#DBAB79")), + common.PrettyLimit(string(b), 48)) + } c.mu.Unlock() return v.value, true diff --git a/internal/server/backend_cache.go b/internal/server/backend_cache.go index e6f1050..2b69322 100644 --- a/internal/server/backend_cache.go +++ b/internal/server/backend_cache.go @@ -11,27 +11,27 @@ type CacheBackend struct { } func (b *CacheBackend) Get(key string) (res string, err error) { - return b.get("val::" + key) + return b.getString("val::" + key) } func (b *CacheBackend) GetHash(key string) (res string, err error) { - return b.get("hash::" + key) + return b.getString("hash::" + key) } func (b *CacheBackend) Set(key, value string, ttl time.Duration) error { - b.cache.Set("val::"+key, value, ttl) + b.cache.Set("val::"+key, []byte(value), ttl) return nil } func (b *CacheBackend) SetHash(key, value string, ttl time.Duration) error { - b.cache.Set("hash::"+key, value, ttl) + b.cache.Set("hash::"+key, []byte(value), ttl) return nil } -func (b *CacheBackend) get(key string) (res string, err error) { +func (b *CacheBackend) getString(key string) (res string, err error) { if v, ok := b.cache.Get(key); ok { - if r, o := v.(string); o { - res = r + if r, o := v.([]byte); o { + res = string(r) } else { err = b.errCast }