473,569 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpRuntime.Cac he

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.Cac he 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"+Rand omValue;
if(HttpRuntime. Cache[key]==null)
{
Usuario miUser=new Usuario(); // by default, i initialize all private
fields in the constructor.
HttpRuntime.Cac he.Insert(key,m iUser,null,Date Time.Now.AddHou rs(1),TimeSpan. Zero);
miUser=Http.Run time.Cache[key];
}
else
{
Usuario miUser=Http.Run time.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 3216
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 = GetUserFromCach e();
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 =GetUserFromCac he(); 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*****@hotmai l.com> wrote in message
news:e$******** ******@TK2MSFTN GP03.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.Cac he 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"+Rand omValue;
if(HttpRuntime. Cache[key]==null)
{
Usuario miUser=new Usuario(); // by default, i initialize all private
fields in the constructor.

HttpRuntime.Cac he.Insert(key,m iUser,null,Date Time.Now.AddHou rs(1),TimeSpan. Zero);
miUser=Http.Run time.Cache[key];
}
else
{
Usuario miUser=Http.Run time.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
2366
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 - not with the built in gizmo). The session times out after 30 minutes. The problem : User may take longer than 30 minutes to fill out the form....
2
7961
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. However how do I check the maxRequestLength value through code? Let me set a bit of background. I don't actually have any ASPX pages I have
0
1452
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 compilation debug attribute is set to "true" in the configuration, then the framework doesn't seem to timeout requests (probably because this might be...
2
1808
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 need to reference a file on the server. Normally, I'd use Server.MapPath to get the file reference, but I can't do that within the thread. What...
2
8493
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 HttpRuntimeSection. Thanks.
1
2415
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 into server cache rather than hit the DB each time, since the data does not change for at least a day.
0
974
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 this doesn't seem to be possible. Am I doing something wrong? Is multiple instances of this cache object even allowed, or is it application wide?
5
4193
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 file when it (re)starts. If it 's not present, it retrieves it from a remote service and caches it locally. If it's not advisable, what is the...
6
5169
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 the dataset out of the cache. the application is under heavy hits, and is set to email me on every error. and once or twice every month I get these...
0
7609
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...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6278
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...
1
5504
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...
0
5217
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...
0
3651
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.