1
0

Added myself to contributors. Moved tests to Items()

This commit is contained in:
Christoph Petrausch 2016-11-28 08:04:39 +01:00
parent f9be2c1abe
commit bec54ffe0d
3 changed files with 3 additions and 18 deletions

View File

@ -6,3 +6,4 @@ code was contributed.)
Dustin Sallings <dustin@spy.net>
Jason Mooberry <jasonmoo@me.com>
Sergey Shepelev <temotor@gmail.com>
Christoph Petrausch <chrobbert@gmail.com>

View File

@ -1022,22 +1022,6 @@ func (c *cache) Items() map[string]Item {
return m
}
// Returns all not expired items in the cache. This method is save to use with
// an active janitor since it copies the underlying map. Therefore method is
// costly in terms of time and memory. You can read while using this method but
// not write. Use with caution.
func (c *cache) GetNotExpiredItems() map[string]Item {
retMap := make(map[string]Item, c.ItemCount())
c.mu.RLock()
for key, item := range c.items{
if !item.Expired() {
retMap[key] = item
}
}
c.mu.RUnlock()
return retMap
}
// Returns the number of items in the cache. This may include items that have
// expired, but have not yet been cleaned up.
func (c *cache) ItemCount() int {

View File

@ -1254,7 +1254,7 @@ func TestCacheGetAllNotExpiredItems(t *testing.T) {
tc.Set("b", "b", DefaultExpiration)
tc.Set("c", "c", time.Millisecond*1)
time.Sleep(time.Millisecond*2)
allNotExpiredItems := tc.GetNotExpiredItems()
allNotExpiredItems := tc.Items()
if len(allNotExpiredItems) != 2 {
t.Error("There are more or less items in the result than the two unexpired.")
}
@ -1710,7 +1710,7 @@ func BenchmarkGetAllNotExpiredItems(b *testing.B) {
}
b.ResetTimer()
for j:= 0; j < b.N; j++{
tc.GetNotExpiredItems()
tc.Items()
}
})
}