473,587 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cache problem

Hi,

I'm using the cache block of the enterprise lib Jan. 2006.

There is somethings strange going on.

I add a varable to the cache, let's say the string myData.
string myData = "1111111";
primitivesCache .Add("Key1", myData, CacheItemPriori ty.Normal, null, new
SlidingTime(Tim eSpan.FromMinut es(15)));

When I do after this line this:
myData = "*****";

And I get my data out of the cache manager then myData has the value of
*********. I also tried to load it inside an other variable. Again the
value is the same.

How is it posible that the data in the cache is changed? Or not added
liked I did?

Thanks!
Arjen

Aug 29 '06 #1
5 2115

Arjen wrote:
Hi,

I'm using the cache block of the enterprise lib Jan. 2006.

There is somethings strange going on.

I add a varable to the cache, let's say the string myData.
string myData = "1111111";
primitivesCache .Add("Key1", myData, CacheItemPriori ty.Normal, null, new
SlidingTime(Tim eSpan.FromMinut es(15)));

When I do after this line this:
myData = "*****";

And I get my data out of the cache manager then myData has the value of
*********. I also tried to load it inside an other variable. Again the
value is the same.

How is it posible that the data in the cache is changed? Or not added
liked I did?
Please post a short but complete program that demonstrates your
problem. See Jon Skeet's page for a description of what constitutes a
"short but complete program":

http://www.yoda.arachsys.com/csharp/complete.html

Aug 29 '06 #2
Well, I found the problem... still strange...
I add an item to the cache.
After that I change the item, and also the item in the cache is changed
(why?).
Now I have made a copy of the variable after I add it to the cache.
This works fine.

Thanks.
Arjen
Bruce Wood wrote:
Arjen wrote:
Hi,

I'm using the cache block of the enterprise lib Jan. 2006.

There is somethings strange going on.

I add a varable to the cache, let's say the string myData.
string myData = "1111111";
primitivesCache .Add("Key1", myData, CacheItemPriori ty.Normal, null, new
SlidingTime(Tim eSpan.FromMinut es(15)));

When I do after this line this:
myData = "*****";

And I get my data out of the cache manager then myData has the value of
*********. I also tried to load it inside an other variable. Again the
value is the same.

How is it posible that the data in the cache is changed? Or not added
liked I did?

Please post a short but complete program that demonstrates your
problem. See Jon Skeet's page for a description of what constitutes a
"short but complete program":

http://www.yoda.arachsys.com/csharp/complete.html
Aug 29 '06 #3
What type is the variable?

Is it a string, like the code in your original post? Or is it one of
your own classes? If it is an object of your own type (class) then I
know why....

Arjen wrote:
Well, I found the problem... still strange...
I add an item to the cache.
After that I change the item, and also the item in the cache is changed
(why?).
Now I have made a copy of the variable after I add it to the cache.
This works fine.

Thanks.
Arjen
Bruce Wood wrote:
Arjen wrote:
Hi,
>
I'm using the cache block of the enterprise lib Jan. 2006.
>
There is somethings strange going on.
>
I add a varable to the cache, let's say the string myData.
string myData = "1111111";
primitivesCache .Add("Key1", myData, CacheItemPriori ty.Normal, null, new
SlidingTime(Tim eSpan.FromMinut es(15)));
>
When I do after this line this:
myData = "*****";
>
And I get my data out of the cache manager then myData has the value of
*********. I also tried to load it inside an other variable. Again the
value is the same.
>
How is it posible that the data in the cache is changed? Or not added
liked I did?
Please post a short but complete program that demonstrates your
problem. See Jon Skeet's page for a description of what constitutes a
"short but complete program":

http://www.yoda.arachsys.com/csharp/complete.html
Aug 29 '06 #4
Hi,

It's an arraylist with my own objects (classes).
So, it sounds like you know why...

Thanks,
Arjen
Bruce Wood wrote:
What type is the variable?

Is it a string, like the code in your original post? Or is it one of
your own classes? If it is an object of your own type (class) then I
know why....

Arjen wrote:
Well, I found the problem... still strange...
I add an item to the cache.
After that I change the item, and also the item in the cache is changed
(why?).
Now I have made a copy of the variable after I add it to the cache.
This works fine.

Thanks.
Arjen
Bruce Wood wrote:
Arjen wrote:
Hi,

I'm using the cache block of the enterprise lib Jan. 2006.

There is somethings strange going on.

I add a varable to the cache, let's say the string myData.
string myData = "1111111";
primitivesCache .Add("Key1", myData, CacheItemPriori ty.Normal, null, new
SlidingTime(Tim eSpan.FromMinut es(15)));

When I do after this line this:
myData = "*****";

And I get my data out of the cache manager then myData has the value of
*********. I also tried to load it inside an other variable. Again the
value is the same.

How is it posible that the data in the cache is changed? Or not added
liked I did?
>
Please post a short but complete program that demonstrates your
problem. See Jon Skeet's page for a description of what constitutes a
"short but complete program":
>
http://www.yoda.arachsys.com/csharp/complete.html
Aug 30 '06 #5
It's because what is cached is a _reference_ to the object instance.
Class instance are _reference types_, so your local variable and the
cache both store the same thing: a reference (or, if you prefer, a
pointer) to the same object in memory. Change the state (contents) of
the object, and it changes in both places because there is only one
object.

If you want to cache a copy of the object, not a reference to the same
object you're holding, then your class has to implement ICloneable and
you have to cache myObject.Clone( ), not myObject.

Arjen wrote:
Hi,

It's an arraylist with my own objects (classes).
So, it sounds like you know why...

Thanks,
Arjen
Bruce Wood wrote:
What type is the variable?

Is it a string, like the code in your original post? Or is it one of
your own classes? If it is an object of your own type (class) then I
know why....

Arjen wrote:
Well, I found the problem... still strange...
I add an item to the cache.
After that I change the item, and also the item in the cache is changed
(why?).
Now I have made a copy of the variable after I add it to the cache.
This works fine.
>
Thanks.
Arjen
>
>
Bruce Wood wrote:
Arjen wrote:
Hi,
>
I'm using the cache block of the enterprise lib Jan. 2006.
>
There is somethings strange going on.
>
I add a varable to the cache, let's say the string myData.
string myData = "1111111";
primitivesCache .Add("Key1", myData, CacheItemPriori ty.Normal, null, new
SlidingTime(Tim eSpan.FromMinut es(15)));
>
When I do after this line this:
myData = "*****";
>
And I get my data out of the cache manager then myData has the value of
*********. I also tried to load it inside an other variable. Again the
value is the same.
>
How is it posible that the data in the cache is changed? Or not added
liked I did?

Please post a short but complete program that demonstrates your
problem. See Jon Skeet's page for a description of what constitutes a
"short but complete program":

http://www.yoda.arachsys.com/csharp/complete.html
Aug 30 '06 #6

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

Similar topics

3
32837
by: Bite My Bubbles | last post by:
I found the answer! It is a IIS 6 /ASP problem http://support.microsoft.com/default.aspx?scid=kb;en-us;332075
1
2500
by: Joe Fallon | last post by:
I am trying to setup a cache that refreshes itself every hour. (My sample code is for every minute so I can test it.) I have found some examples that I thought worked but they all seem to fail. (They only work when I click the submit button - not when the cache expires.) In my Login form I have: Global.AddItemToCache("CacheTime", Date.Now,...
13
1773
by: Fernando Chilvarguer | last post by:
Hi, I'm retriving data from a database and storing it on the Cache Object using the following code: HttpContext.Current.Cache.Insert( cacheItemKey, contentDS, //THE DATASET WITH MY DATA null, DateTime.Now.AddSeconds(600),
6
1759
by: Adam | last post by:
On an xp machine, the caching works as expected. I have deployed to a win2k server, and an item I add to the cache expires almost immediately some times and in under a minute in other times. The aspnet_wp process is not restarting during this time, and there are no other requests, so nothing should be clearing this out. I have added a...
3
1916
by: Aryan | last post by:
Hi, I have problem related to Caching of data. I am reading large xml file and putting this xml in dataset, since this dataset will contain many datatable's inside. And each datatable might be big in data. Each user will contain its seperate xml file, so when I create xml file for each user, I am putting this xml DataSet in Cache object, but...
1
1392
by: =?Utf-8?B?ZGF2ZQ==?= | last post by:
I have an asp.net project with a business layer (project) that has a class called references. It loads up a data set and stores in cache with the following code. _cached = CType(HttpContext.Current.Cache("cached"), String) If HttpContext.Current.Cache("cached") Is Nothing Or _cached <> "loaded" Then...
2
2664
by: moondaddy | last post by:
I had to repost this because I had to update and change my msdn alias. I will re-ask the question and clarify a few things that were not clear before. This code is all executed on my dev machine running winXP sp2 and VS2005. I'm using a c# 2.0 winforms app which talks to a c#2.0 asp.net app that also contains 1 web service. Note: the...
5
2269
by: J055 | last post by:
Hi The following code works on my develeopment machine using the VS web server. When I run the application on 2 other Windows 2003/IIS 6 servers no caching seems to take place at all. Can someone explain what I might be doing wrong or what to look out for? What's the differece between IIS and VS web server? The IIS servers seem to have...
0
2419
by: Hypnotik | last post by:
My program is to simulate cache memory. I read in the info from 2 external files, 1) access 2) data in memory. When I read the information in I display the info...and it is all correct. However when I attempt to display the info in main anywhere the info is incorrect. I thought it might be a problem while I was reading the data in, but it...
0
7920
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...
0
8347
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...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6626
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...
0
5394
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
3844
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
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
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.