Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / June 2005

Tip: Looking for answers? Try searching our database.

ASP.Net Cache & Multiple threads.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Rolls - 22 Jun 2005 10:26 GMT
I need to cache user data within an HttpModule so I've overloaded
OnAuthenticate I retrieve the LOGON_USER server variable as the site must be
configured for integrated auth and attempt to locate a cache entry based on
the user name (we it's a cookie in reality). If I can't find the item I run
off to AD retrieve some data and put it into the cache so far so good!

however the OnAuthenticate is called on different threads as the web browser
(IE) request the main pages subsidiary files jpg's, css etc.

1. So my question is how would handle different threads not finding the item
and running of to AD to retrieve the user data?

2. If I where to use a lock around retrieving and adding I'd essentially
block access for other users who potentially live in the cache but can't
access it for getting stuff out?

Regards
Robert.
Alvin Bruney [MVP - ASP.NET] - 26 Jun 2005 06:38 GMT
1 is not really an issue. Each request checks the cache. If it is not there,
it is updated so the next thread gets the updated copy. (for the most part -
there is a nasty concurrency issue that we'll tackle in 2)

2 you will need to wrap the cache object with a function that locks the
cache when it is being written. This will block other threads while the data
is updated. If the update is not frequent, this is not a problem. however,
if it is or if there are a lot of cache misses, you could bottle neck. One
solution is to lock on a string object that represents the cache. This is
much cheaper than locking on the cache object itself. so essentially, the
string represents the cache. you lock the string and update the cache. there
is some slight overhead but it fairs rather well under moderate loads - at
least better than locking the cache object itself.

Signature

Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc

>I need to cache user data within an HttpModule so I've overloaded
>OnAuthenticate I retrieve the LOGON_USER server variable as the site must
[quoted text clipped - 14 lines]
> Regards
> Robert.
Robert Rolls - 26 Jun 2005 10:16 GMT
Is it acceptable to potentially stop other requests where the cache read
would be successful? I.e. two requests are being serviced simultaneously one
connection has requested files before and hence the cache will contain the
users AD data, the other connection data isn't in the cache but will now
lock the cache whilst the write occurs? This is probably on time where the
ReaderWriterLock may be an ideal candidate.

Regards
Robert.

>1 is not really an issue. Each request checks the cache. If it is not
>there, it is updated so the next thread gets the updated copy. (for the
[quoted text clipped - 30 lines]
>> Regards
>> Robert.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.