c# - Does a cache need to synchronized? -


This probably sounds like a naive question, but I had a discussion with a colleague where I argued that there is no one As a genuine need for a pouch-safe / synchronized cache, I would think that it does not matter which one is putting a value, because the value for the given key should be "static" (it is coming from the same source) In the end). If the price can easily change, the cash itself does not seem to be useful (if you keep in mind that the price is "currently true" you should go to the original source).

The main reason is that I need to get at least GET synchronization that if remembering in the cache is very expensive and you do not want to get a value to put it back in several carriage. Still, you need something which actually blocks all the consumers during a reading-fetched cycle

Anyhow, my assumption of working is that any {key , Value} a hash for the combination its nature is thread-safe, the value is either zero or something that does not matter which goes there "first" to write

The question is: what Is this a reasonable assumption?

UPDATE: The actual scope of my question is very simple ID-> value style cache (or {parameter} -> {calculated value} no matter what's written in the cache, the value will be the same and we The actual graph of the object is not relevant and the cache usually lasts longer.

Post-text "itemprop =" text ">

For most implementations of the hash you have to synchronize If the hash table needs to be expanded / re-forced, what if two threads are trying to add to the hash table, where the key is different, but the hash collides? They are both different ways You can modify the slot in the hash table at the same time. Suppose you are using a hash table to apply your cache (which you indicate in your question) and I suggest reading a bit about the detail if you are not already familiar with this.


Comments