diff --git a/cache.go b/cache.go index 51f1876..4f7630f 100644 --- a/cache.go +++ b/cache.go @@ -118,10 +118,10 @@ func (c *cache) Replace(k string, x interface{}, d time.Duration) error { func (c *cache) Rename(oldk, newk string) error { c.mu.Lock() defer c.mu.Unlock() - item, found := c.get(oldk) - if !found { + if _, found := c.get(oldk); !found { return fmt.Errorf("Item %s doesn't exist", oldk) } + item := c.items[oldk] delete(c.items, oldk) c.items[newk] = item return nil diff --git a/cache_test.go b/cache_test.go index 3146ad7..57c09be 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1140,8 +1140,8 @@ func TestReplace(t *testing.T) { func TestRename(t *testing.T) { tc := New(DefaultExpiration, 0) err := tc.Rename("foo", "bar") - if err != nil { - t.Error(err) + if err == nil { + t.Error("Renamed foo when it shouldn't exist") } tc.Set("foo", 123, DefaultExpiration) err = tc.Rename("foo", "bar")