ttlcache icon indicating copy to clipboard operation
ttlcache copied to clipboard

Add Version method to item type

Open swithek opened this issue 2 years ago • 1 comments

It should return a uint64 that determines how many times an item has been updated. This method may be useful in situations when a task's execution depends on whether the item has changed or not and when due to the duration of another task a transaction/mutex isn't acceptible.

item := cache.Get("key")
version := item.Version()
// long task
if item.Version() == version {
     // execute only if the item hasn't been updated during the long task's execution
}

swithek avatar Mar 29 '22 13:03 swithek

Alternatively, this can also be part of the object being put into the cache now that we have generics support.

ReneKroon avatar Mar 29 '22 17:03 ReneKroon