2
0

Add O(1) ItemCount method to retrieve items currently in the cache map (whether expired and not cleaned up or not)

This commit is contained in:
Patrick Mylund Nielsen
2013-04-18 14:32:01 -04:00
parent d5d03c28d4
commit c9f5754801
2 changed files with 20 additions and 0 deletions
+10
View File
@@ -49,6 +49,7 @@ type unexportedInterface interface {
DecrementFloat64(string, float64) (float64, error)
Delete(string)
DeleteExpired()
ItemCount() int
Flush()
Save(io.Writer) error
SaveFile(string) error
@@ -933,6 +934,15 @@ func (c *cache) LoadFile(fname string) error {
return fp.Close()
}
// 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 {
c.Lock()
n := len(c.items)
c.Unlock()
return n
}
// Delete all items from the cache.
func (c *cache) Flush() {
c.Lock()