jellydator / ttlcache

An in-memory cache with item expiration and generics
MIT License
883 stars 115 forks source link

Ensure that GetOrSet and GetAndDelete are properly locked #97

Closed swithek closed 10 months ago

swithek commented 1 year ago

The problem: Currently, GetOrSet/GetAndDelete methods call an internal get method, which locks the mutex and unlocks it before returning, and then call the Set/Delete method, which also locks the mutex and unlocks it before returning. There's a small time gap between the get call and the set/delete call when the mutex isn't locked during which it's possible that the data might be altered. We should probably create another internal get method that would do no locking internally, allowing us to lock the mutex in GetOrSet/GetAndDelete.

swithek commented 1 year ago

Related: #81

swithek commented 10 months ago

Fixed in https://github.com/jellydator/ttlcache/pull/107