473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Lock cache while updating it?

I am caching some data in VB.NET using System.Web.Caching, is it possible to
lock the cache so that other sessions attempting to access the same cache
wait when it is being updated? I have the cache using a sliding timeout and
a dependency on the text file its data is extracted from.
If it's relevant, based on current statistics, I do not expect more than
about 400 people to be accessing the web site at the same time.
I've seen it appears easy in C# but I couldn't find anything regarding VB.

Andrew
Nov 21 '05 #1
13 2310
Andrew,

You make me curious, why would you do that? Seems to me a strange solution,
because you should than make a mechanisme for those other 399 who try to
access that cache in my idea. When it is, than what it the action on that
catch?

I am real curious about this how you did that.

Cor
Nov 21 '05 #2
Cor Ligthert wrote:
Andrew,

You make me curious, why would you do that? Seems to me a strange
solution, because you should than make a mechanisme for those other
399 who try to access that cache in my idea. When it is, than what it
the action on that catch?

I am real curious about this how you did that.

Cor


The cached data is a lookup table which has the same data for every user.
The cache applies to the web application rather than per-session. Unless I
have misunderstood the docs.

Andrew
Nov 21 '05 #3
Andrew,

Clear,

Is it than not something as updating the tables, create a page to kill the
cache and let it go again, where I assume that the cache is created when it
is nothing?

I never used that cache, however that is from what I understand from it,
would probably as first try to do it.

Cor
Nov 21 '05 #4
> Is it than not something as updating the tables, create a page to
kill the cache and let it go again, where I assume that the cache is
created when it is nothing?


Imagine this scenario:-
--------------------------
session1 starts and finds the cache is nothing and starts parsing the data
to create the cache

While session1 is parsing the data, session2 starts and finds the cache is
nothing, so it starts parsing the data to create the cache

session1 finishes parsing the data and creates the cache

session2 finishes parsing the data and creates the cache, except session1 is
still writing the cache so something goes wrong
--------------------------

Preferred scenario:-

session1 starts and finds the cache is nothing, locks the cache and starts
parsing the data to create the cache

While session1 is parsing the data, session2 starts and finds the cache is
locked, so it waits until the cache is unlocked.

Andrew
Nov 21 '05 #5
JD
The MSDN docs say Cache is thread safe.

"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:eu**************@TK2MSFTNGP15.phx.gbl...
I am caching some data in VB.NET using System.Web.Caching, is it possible to lock the cache so that other sessions attempting to access the same cache
wait when it is being updated? I have the cache using a sliding timeout and a dependency on the text file its data is extracted from.
If it's relevant, based on current statistics, I do not expect more than
about 400 people to be accessing the web site at the same time.
I've seen it appears easy in C# but I couldn't find anything regarding VB.

Andrew

Nov 21 '05 #6
Andrew,

Did you test this and did it work as you describe. For me is the problem
that somebody once wrote here that an aspnet dll is running itself
automaticly on more threads for sessions.

When that is not true, than in my opinion can the effect not be as you
write.
However I never saw any documentation which tells something about the proces
of a webapplication dll.

Sorry

Cor
Nov 21 '05 #7
JD wrote:
The MSDN docs say Cache is thread safe.


How do I use that to make other threads pause when one thread is updating
the cache?

However, looking through the docs about thread safety lead me to SyncLock,
which I think is what I want.

Andrew
Nov 21 '05 #8
JD
The Cache automatically synchronizes access to the data. I believe it uses a
multireader, single writer lock. In other words you don't have to do
anything.

"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
JD wrote:
The MSDN docs say Cache is thread safe.


How do I use that to make other threads pause when one thread is updating
the cache?

However, looking through the docs about thread safety lead me to SyncLock,
which I think is what I want.

Andrew

Nov 21 '05 #9
JD
But let me emphasize, the block of code that does -> {check if the cache
data is Nothing and if it is Nothing do the update to cache } must be
synchonized.
"JD" <an**@anon.anon> wrote in message
news:uQ**************@TK2MSFTNGP10.phx.gbl...
The Cache automatically synchronizes access to the data. I believe it uses a multireader, single writer lock. In other words you don't have to do
anything.

"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
JD wrote:
The MSDN docs say Cache is thread safe.


How do I use that to make other threads pause when one thread is updating the cache?

However, looking through the docs about thread safety lead me to SyncLock, which I think is what I want.

Andrew


Nov 21 '05 #10
> "JD" <an**@anon.anon> wrote in message
news:uQ**************@TK2MSFTNGP10.phx.gbl...
The Cache automatically synchronizes access to the data. I believe
it uses a multireader, single writer lock. In other words you don't
have to do anything.
JD wrote: But let me emphasize, the block of code that does -> {check if the
cache data is Nothing and if it is Nothing do the update to cache }
must be synchonized.


So, before I start reading the wrong things and getting myself confused,
should I be looking at System.Threading.Mutex?

(I'm thinking that maybe I should have one object in the application
accessible to all sessions, but I can't figure out how to do that.)

What I have boils down to

cachedData=cache("thesaurus")
if cachedData is nothing then
' apply some sort of lock to the non-existent cache
' build and cache cachedData
' release lock
end if

What I want to happen is that the other threads (if any at that time) wait
at line 'cachedData=cache("thesaurus")' until the lock is released because
building the data may take some time - it would be a waste of time for
several sessions to simultaneously do that and then wait in a queue for each
to write identical data to the cache.

Oh, other info: I'm using VB.NET in the 1.1 .net framework on WS2003.

Andrew
Nov 21 '05 #11
JD
1. cachedData=cache("thesaurus")
2. if cachedData is nothing then
3. ' apply some sort of lock to the non-existent cache
4. ' build and cache cachedData
5. ' release lock
6. end if

You need the lock outside everything in the code above. Because at line 3,
two threads could have gotten here at the same time and one thread acquired
the lock populating the cache, then thread number two would acquire the lock
and repopulate the cache. Look at the code below.

' apply some sort of lock to the non-existent cache
cachedData=cache("thesaurus")
if cachedData is nothing then
' build and cache cachedData
end if
' release lock

Or you could do below and I think it is more efficient:

cachedData=cache("thesaurus")
if cachedData is nothing then
' apply some sort of lock to the non-existent cache
if cachedData is nothing then
' build and cache cachedData
end if
' release lock
end if

Did you look at populating the cache once during application startup event?


"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:es*************@TK2MSFTNGP09.phx.gbl...
"JD" <an**@anon.anon> wrote in message
news:uQ**************@TK2MSFTNGP10.phx.gbl...
The Cache automatically synchronizes access to the data. I believe
it uses a multireader, single writer lock. In other words you don't
have to do anything.
JD wrote:
But let me emphasize, the block of code that does -> {check if the
cache data is Nothing and if it is Nothing do the update to cache }
must be synchonized.


So, before I start reading the wrong things and getting myself confused,
should I be looking at System.Threading.Mutex?

(I'm thinking that maybe I should have one object in the application
accessible to all sessions, but I can't figure out how to do that.)

What I have boils down to

cachedData=cache("thesaurus")
if cachedData is nothing then
' apply some sort of lock to the non-existent cache
' build and cache cachedData
' release lock
end if

What I want to happen is that the other threads (if any at that time) wait
at line 'cachedData=cache("thesaurus")' until the lock is released because
building the data may take some time - it would be a waste of time for
several sessions to simultaneously do that and then wait in a queue for

each to write identical data to the cache.

Oh, other info: I'm using VB.NET in the 1.1 .net framework on WS2003.

Andrew

Nov 21 '05 #12
JD wrote:
Or you could do below and I think it is more efficient:

cachedData=cache("thesaurus")
if cachedData is nothing then
' apply some sort of lock to the non-existent cache
if cachedData is nothing then
' build and cache cachedData
end if
' release lock
end if
Thanks, I'll give that a go.
Did you look at populating the cache once during application startup
event?


I thought about that, but I suspect that changing the file the cache depends
on would then cause the application to restart which would destroy any
existing sessions(?)

Thanks for bearing with me with this, I think I'm trying to do to many
things in work at the same time so my brain isn't working very well.

Andrew
Nov 21 '05 #13
JD
> I thought about that, but I suspect that changing the file the cache
depends
on would then cause the application to restart which would destroy any
existing sessions(?)

If the file itself is under the web application directory, it may cause the
application to restart regardless. It depends on what types of files ASP.NET
watches to kick off a restart or if it just watches all files?
Nov 21 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: xixi | last post by:
can someone explain to me what is internal p lock, internal s lock, internal v lock? when i have IS lock or IX lock , i always have these internal locks together for the application handle ...
9
by: Jane | last post by:
Our db2diag.log is full of messages like this: 2004-05-31-17.15.10.383766 Instance:tminst1 Node:000 PID:394948(db2agent (TMDB1) 0) TID:1 Appid:GA140956.EF26.03A4B1202647 data management ...
6
by: n_o_s_p_a__m | last post by:
I have seen some debate but am not clear on what the problematic implications of the expression lock(this) are. Microsoft seems to advocate it, but others seem to be against it. Pros and cons? ...
4
by: Mat | last post by:
Hi, I've stumbled onto a problem when using the caching object in ASP.Net. I'm placing a static dataset to the cache as the data only changes once a day. Whilst writing to the cache I'm using...
5
by: Lloyd Dupont | last post by:
in an ASP.NET page I have some static method which get value for the cache or, if the cache is empty, query the database, put the value in the cache and return it. because ASP.NET is thread...
3
by: Raj | last post by:
I created a refresh deferred MQT, and during full refresh there were 4 or 5 lock waits, all waiting on a 'S' lock on Internal Catalog Cache ? Can some one explain how to prevent this from happening?
2
by: archana | last post by:
Hi all, I am having application wherein i am using asynchronous programming and using callback i am updating one label control. My question is can i use lock statment to lock control. If yes...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.