Asdfg
Asdfg

Reputation: 12248

is this good implementation of Multithreaded Caching in .Net?

While implementing Multithreaded Cache, i found this article on MSDN.

http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx

This is for windows appliation using framework 4.0. My main concern is Thread Safety. Currently i am using MemoryCache and i know it is not Thread Safe. So is the provided implementation a better way to implement Multithreaded Caching?

Please advice.

Upvotes: 1

Views: 437

Answers (2)

to StackOverflow
to StackOverflow

Reputation: 124814

Currently i am using MemoryCache and i know it is not Thread Safe.

MemoryCache is thread-safe - look at the Thread Safety section in the MSDN documentation.

Of course the items you put into MemoryCache may not be thread-safe, which is another story. In many cases MemoryCache is used to store immutable elements, which will be thread-safe.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039598

I don't quite see the relation between a ReaderWriterLockSlim and caching. This class is used to synchronize the access to a shared resource in a multithreaded application. For implementing data caching I would recommend you taking a look at the System.Runtime.Caching namespace.

Upvotes: 2

Related Questions