473,414 Members | 1,628 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,414 software developers and data experts.

HttpRuntime.Cache

Hello
First of all, sorry for my bad english ;)

I have a USER class that i create to every user that enters the website (not
neccesarily logged in). At the same time i insert it into a the
HttpRuntime.Cache if it doesn't exist.
In every request i verify if the user is in the Cache so i don't have to
create it again. If it exists, i instantiate an USER object with the Cache
object already saved.
this is more or less the idea

string key="user"+RandomValue;
if(HttpRuntime.Cache[key]==null)
{
Usuario miUser=new Usuario(); // by default, i initialize all private
fields in the constructor.
HttpRuntime.Cache.Insert(key,miUser,null,DateTime. Now.AddHours(1),TimeSpan.Zero);
miUser=Http.Runtime.Cache[key];
}
else
{
Usuario miUser=Http.Runtime.Cache[key];
}

My question is. If i change one private field value of my instance of the
USER class, will it be changed at the Cache object too? I think it does
'cause i'm referencing that object, not creating a new one (in the else
statement).
Is this OK or WRONG?
What i want is to keep the user object to keep its values along the
application life.

Saludos
May 8 '06 #1
1 3204
It's a fairly simple thing for you to try and find out on your own :)

But your assumption is correct. You are only storing a reference in the
cache, any updates to that reference (or references of the reference) will
be reflected.

On note...

If you do:

User user = GetUserFromCache();
user.FirstName = "New Name";

you'll have updated it in the cache...if the object gets dropped from the
cache however, and you retrieve the user:

User user =GetUserFromCache(); the firstName will go back to what it was
before, because it was never persistend to a store, such as a database..

Karl

--
http://www.openmymind.net/

"Jose Fernandez" <pp*****@hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
Hello
First of all, sorry for my bad english ;)

I have a USER class that i create to every user that enters the website
(not neccesarily logged in). At the same time i insert it into a the
HttpRuntime.Cache if it doesn't exist.
In every request i verify if the user is in the Cache so i don't have to
create it again. If it exists, i instantiate an USER object with the Cache
object already saved.
this is more or less the idea

string key="user"+RandomValue;
if(HttpRuntime.Cache[key]==null)
{
Usuario miUser=new Usuario(); // by default, i initialize all private
fields in the constructor.

HttpRuntime.Cache.Insert(key,miUser,null,DateTime. Now.AddHours(1),TimeSpan.Zero);
miUser=Http.Runtime.Cache[key];
}
else
{
Usuario miUser=Http.Runtime.Cache[key];
}

My question is. If i change one private field value of my instance of the
USER class, will it be changed at the Cache object too? I think it does
'cause i'm referencing that object, not creating a new one (in the else
statement).
Is this OK or WRONG?
What i want is to keep the user object to keep its values along the
application life.

Saludos

May 8 '06 #2

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

Similar topics

0
by: Ross Dempster | last post by:
Hi everyone, this is quite involved but if anyone can help (or just likes a challenge!) i would very much appreciate it. Quick intro : I have forms based authentication (though i do it manually...
2
by: Peter Row | last post by:
Hi, To allow users to upload files larger than 4MB in size I added: <httpRuntime maxRequestLength="102400" executionTimeout="600" /> ...to my web.config file. Fair enough this works fine....
0
by: Peter Jaffe | last post by:
I had noticed a number of people posting that they where having trouble getting the Web.config httpRuntime executionTimeout attribute to work as expected. I realized today that if the...
2
by: Random | last post by:
I am running some threaded operations within my ASP.NET app, in order to add some data to the Cache. I know enough to use the HttpRuntime.Cache instead of the HttpContext.Cache, but my operations...
2
by: sa.cesare | last post by:
Is there any means to get httpRuntime section in Page_Load()? WebConfigurationManager.GetSection("system.web/httpRuntime") returns some kind of RuntimeWrapper(nowhere documented) instead of...
1
by: Bishop | last post by:
I have googled to try and find an answer to this issue, but everything I found beats around the bush. I have a web service that calls a DLL. In the DLL, I want to cache the small table data...
0
by: mr.peteryu | last post by:
I have an object that is composed of 3 different hashtables. I am not planning on using this in a web app. I tried to replace these Hashtables with 3 different HttpRunTime.Cache objects, but...
5
by: | last post by:
Is it advisable to store my own data as XML in the folder returned by HttpRuntime.CodeGenDir? (i.e. in "Temporary ASP.NET Files") Each web service on the server must try to read its own cached...
6
by: =?Utf-8?B?emlubw==?= | last post by:
in asp.net 2, I load a dataset from the Cache object into a local object to use to perform processing. I had been using httpcontext.current.cache and what I noticed is sometime I'm not able to get...
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: 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:
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
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,...
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...
0
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,...
0
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...
0
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...

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.