Put adds a key to the cache. No eviction occurs when memory is over filled or greater than the specified size in the cache. The entire cache is cleared and starts building it again from an empty cache instead.
(key string)
| 123 | // The entire cache is cleared and starts building it again from |
| 124 | // an empty cache instead. |
| 125 | func (c *NoReplKeyCache) Put(key string) { |
| 126 | c.lock.Lock() |
| 127 | if _, ok := c.cache[key]; ok { |
| 128 | c.lock.Unlock() |
| 129 | return |
| 130 | } |
| 131 | if len(c.cache) >= c.size { |
| 132 | c.cache = map[string]struct{}{} |
| 133 | } |
| 134 | c.cache[key] = struct{}{} |
| 135 | c.lock.Unlock() |
| 136 | } |
| 137 | |
| 138 | // Len returns the number of keys in the cache. |
| 139 | func (c *NoReplKeyCache) Len() int { |