Get returns the stored value against the key and when the key was last updated.
(ctx context.Context, key string)
| 273 | |
| 274 | // Get returns the stored value against the key and when the key was last updated. |
| 275 | func (c *FifoCache) Get(ctx context.Context, key string) ([]byte, bool) { |
| 276 | c.totalGets.Inc() |
| 277 | |
| 278 | c.lock.RLock() |
| 279 | defer c.lock.RUnlock() |
| 280 | |
| 281 | element, ok := c.entries[key] |
| 282 | if ok { |
| 283 | entry := element.Value.(*cacheEntry) |
| 284 | if c.validity == 0 || time.Since(entry.updated) < c.validity { |
| 285 | return entry.value, true |
| 286 | } |
| 287 | |
| 288 | c.totalMisses.Inc() |
| 289 | c.staleGets.Inc() |
| 290 | return nil, false |
| 291 | } |
| 292 | |
| 293 | c.totalMisses.Inc() |
| 294 | return nil, false |
| 295 | } |
| 296 | |
| 297 | func sizeOf(item *cacheEntry) uint64 { |
| 298 | return uint64(int(unsafe.Sizeof(*item)) + // size of cacheEntry |