BitFaster.Caching
BitFaster.Caching copied to clipboard
Mitigate value type torn writes during LRU update
trafficstars
- Since update and delete are performed within a lock, threads pushing items through the queues will not see the torn write.
- Reads during update are susceptible. Key concern here is to avoid a lock during the read because this will lead to lock contention for high frequency reads.
- TODO: the new item must be enqueued:
- If it is, the queue is polluted wasting some capacity (potentially evicting valid items) and the old item will then age out.
- If not, wasAccessed in the queue will not reflect the dictionary and the policy is broken
- Alternatives here would be
- To add the new item to the dictionary (so readers see the new value without tearing), then update the old item, the update the dictionary a second time.
- Somehow make the value in the queue updatable