Does this simple cache class need thread synchronization?
<p>Does this simple cache class need thread synchronization ... if I remove the lock _syncLock statement will encounter any problems? I think i can remove the locks as the references should be updated correctly right? ... BUt i'm think whar happens if client code is iterating over the GetMyDataStructure method and it get replaced?</p>

<p><strong>Edit:</strong> I've replace the GetMyDataStructure with a TryGetValue style method and removed all locking .... this should be ok right?</p>

<pre><code>    public bool TryGetValue(int id, out MyDataStructure myDataStructure)
    {
        return _cache.TryGetValue(id, out myDataStructure);
    }
</code></pre>

<p>Thanks!</p>

<pre><code>public sealed class Cache 
{
    private readonly object _syncLock = new object();
    private IDictionary&lt;int, MyDataStructure&gt; _cache;

    public Cache()
    {
        Refresh();
    }

    public void Refresh()
    {
        lock (_syncLock)
        {
            _cache = DAL.GetMyDataStructure();
        }
    }

    public IDictionary&lt;int, MyDataStructure&gt; **GetMyDataStructure**()
    {
        lock (_syncLock)
        {
            return _cache;
        }
    }
}
</code></pre>
