Return the item if exists else create it. Create should be invoked only once. recreating the object is not supported.
(item CacheItem)
| 113 | // Return the item if exists else create it. |
| 114 | // Create should be invoked only once. recreating the object is not supported. |
| 115 | func (w *autoRefreshCache) GetOrCreate(item CacheItem) (CacheItem, error) { |
| 116 | if val, ok := w.lruMap.Get(item.ID()); ok { |
| 117 | return val.(CacheItem), nil |
| 118 | } |
| 119 | |
| 120 | w.lruMap.Add(item.ID(), item) |
| 121 | return item, nil |
| 122 | } |
| 123 | |
| 124 | // This function is called internally by its own timer. Roughly, it will list keys and for each of the keys, call |
| 125 | // syncCb, which tells us if the item has been updated. If it has, then do a remove followed by an add. We can get away |