[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

RE: HttpRuntime Cache threading

Joerg Jooss

1/6/2007 12:50:00 PM

Thus wrote Erik,

> Uh... that's pretty shocking. Your sample indicates that I need to
> define my own lock object. What if other libraries also use the app
> cache??? They won't share my lock.
>
> None of the articles I've seen online use locks. If this is true then
> there must be a LOT of buggy web apps out there...

Agreed. Even books like Essential ASP.NET specifically metion that Cache
is thread-safe.

Comparing http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebcachingcacheclas...
and http://msdn2.microsoft.com/en-us/library/system.web.caching....
makes me really wonder -- either the newer documentation is wrong or it is
one truly hideous breaking change...

Cheers,
--
Joerg Jooss
news-reply@joergjooss.de


2 Answers

H@2dC0d32

1/27/2007 2:16:00 AM

0

The cache object you are using in ASP.NET is static.

Do you create an instance of it when you use Cache?
No!

So it is public static (shared in VB.NET), and thread safe.

No need to play wo-doo dance around thread locks with ASP.NET cache :)

Happy coding

*** Sent via Developersdex http://www.develop... ***

Joerg Jooss

1/31/2007 7:18:00 PM

0

Thus wrote H@2dC0d.32,

> The cache object you are using in ASP.NET is static.
>
> Do you create an instance of it when you use Cache? No!
>
> So it is public static (shared in VB.NET), and thread safe.

That's a false conclusion. All relevant Cache methods like Add(), Get(),
Insert() or its indexer are instance methods. Cache is also neither a static
meber in Page, nor in HttpContext.

Personally, I think the Windows SDK docs are simply wrong. So yes, no fiddling
with locks required ;-)

Cheers,
--
Joerg Jooss
news-reply@joergjooss.de