473,799 Members | 3,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET cache object thread safe?

Hi

I have a N-tier ASP.NET application that uses a data access tier to get data
from a database and pass it to the middleware/business tier for
processing/filtering and then passes the modified data to the web tier for
presentaion.

What I would like to do is introduce a cache to the middleware tier to cut
down on the round trips to the database.

The question I have is this. Is the cache threadsafe? I will be accessing it
from two different places in the middleware tier. One to read the cache, the
other to update the cache.

Reading newsgroups I am getting conflicting messages as to whether the cache
is thread safe or not.

I'd appreciate any advice,

Thanks
Macca
Sep 6 '06 #1
1 10363
Macca,

Well, the documentation for the Cache class in the System.Web.Cach ing
namespace declares that the instance is safe for multi-threading. Of
course, this makes sense, given that it is going to be hit by a number of
threads that are processing page requests.

However, I would recommend that you not use the cache in your
middleware. This ties your middleware to ASP.NET, which in general, isn't a
good idea. It doesn't make your routines portable at all, in case you
decide to access your middleware through other means.

I would recommend taking a look at the enterprise library:

http://msdn.microsoft.com/library/?u...ml/EntLib2.asp

In it, I would take a look at the caching application block, which
actually has more features than ASP.NET's caching mechanism:

http://msdn.microsoft.com/practices/...l/caching1.asp

I would also assume that this is thread safe, but if you don't trust it,
the code for the application block is distributed with the library, so you
can make it thread safe, if you wish or you find that it isn't.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Macca" <Ma***@discussi ons.microsoft.c omwrote in message
news:64******** *************** ***********@mic rosoft.com...
Hi

I have a N-tier ASP.NET application that uses a data access tier to get
data
from a database and pass it to the middleware/business tier for
processing/filtering and then passes the modified data to the web tier for
presentaion.

What I would like to do is introduce a cache to the middleware tier to cut
down on the round trips to the database.

The question I have is this. Is the cache threadsafe? I will be accessing
it
from two different places in the middleware tier. One to read the cache,
the
other to update the cache.

Reading newsgroups I am getting conflicting messages as to whether the
cache
is thread safe or not.

I'd appreciate any advice,

Thanks
Macca

Sep 6 '06 #2

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

Similar topics

0
1522
by: Timo | last post by:
I'm trying to make a thread safe object cache without locking. The objects are cached by the id of the data dict given in __new__. Objects are removed from the cache as soon as they are no longer referenced. The type of the data must be a Python dict (comes from an external source). Here's what I've got so far: import time
5
1399
by: stefano mostarda | last post by:
Hi there, I have a question. In my application I have a table which is frequently used to fill a combo. I want to store it in the application or cache object. it is never updated. What's the besta container to improve performance and scalability, Cache or Application object?
4
5370
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 a lock using code like below (just typed this in); Cache thisCache = HttpContext.Current.Cache lock(thisCache)
5
1653
by: eXseraph | last post by:
In application state, we need to use "Application.Lock()" before we write something into Application. My question is do we need use "Application.Lock()" to LOCK the cache before we write into Cache?
1
1420
by: Christopher | last post by:
In one of our ASP.NET Pages, we are starting a new background thread that we do not need to go and get any status on or use after the page finishes. The thread merely does some background stuff on its own and finishes on its own, no feedback back to the user (by design). Within that thread however, some items need to be accessed and/or inserted into the Cache for possible subsequent processing by another page. Many examples I see of...
1
2729
by: William Sullivan | last post by:
I'm trying to nail down some issues with the cache in my application. Currently, I have an object that stands between my business logic and database logic called CacheLogic (cute, no?). Global.asax.cs creates it in Application_Start, initializes it and places it in the cache. During initialization, CacheLogic retrieves data from the DB logic layer and caches it with removal callbacks set. Whenever an object in the business logic layer...
5
2166
by: Joseph Geretz | last post by:
Of course, I can store a C# class instance to the Server Cache (this.Context.Cache). I've tried it. My question is, will this destroy the scalability of my application? My background is VB6. With VB6 we learned very early on that you do *NOT* store VB6 class instances on the server. That is because a VB6 class can only be accessed on the thread on which it is created (thread affinity). This is just incompatible with stateless web...
6
2077
by: O.R.Senthil Kumaran | last post by:
Hi, There is an Open Tracker item against urllib2 library python.org/sf/735515 which states that. urllib / urllib2 should cache the results of 301 (permanent) redirections. This shouldn't break anything, since it's just an internal optimisation from one point of view -- but it's also what the RFC (2616, section 10.3.2, first para) says SHOULD happen. I am trying to understand, what does it mean. Should the original url be avaiable to...
5
4833
by: Max2006 | last post by:
Hi, Since Application collection and Page.Cache can be shared among all sessions, I wonder if they are thread safe? Thank you, Max
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.