Add timestamps an item and inserts it into the cache, overwriting entries that might exist under the same key.
(obj interface{})
| 147 | // Add timestamps an item and inserts it into the cache, overwriting entries |
| 148 | // that might exist under the same key. |
| 149 | func (c *ExpirationCache) Add(obj interface{}) error { |
| 150 | key, err := c.keyFunc(obj) |
| 151 | if err != nil { |
| 152 | return KeyError{obj, err} |
| 153 | } |
| 154 | c.expirationLock.Lock() |
| 155 | defer c.expirationLock.Unlock() |
| 156 | |
| 157 | c.cacheStorage.Add(key, &TimestampedEntry{obj, c.clock.Now()}) |
| 158 | return nil |
| 159 | } |
| 160 | |
| 161 | // Update has not been implemented yet for lack of a use case, so this method |
| 162 | // simply calls `Add`. This effectively refreshes the timestamp. |