Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / May 2006

Tip: Looking for answers? Try searching our database.

2.0 Cache weirdness found (and possibly a solution)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manso - 06 Mar 2006 21:37 GMT
Ok, we've now figured out how to work around what seems to be an overly
aggressive cache scavenging in ASP.NET 2.0. I'm not saying this is a bug but
it's definitely something that has changed since 1.1 and people should be
aware of because it's damn hard to find because you simply repopulate the
cache when it gets emptied.

We had the following code

Current.Cache.Insert("config", objConfig, New
Caching.CacheDependency("c:\mydir\config.xml"))

This code was running fine on 1.1. Cache was never being emptied (unless the
dependant file was changed). I have verified this now by using our logging
framework. Same code constantly gets reset in 2.0, sometimes just after
Cache.Insert when stepping through code. This started when we had to swap to
HttpRuntime.Cache but it's the same with HttpContext.Current.Cache - we just
happened to notice it when trying HttpRuntime.Cache because we needed to
access it from a TimerCallback function.

We changed to

Current.Cache.Insert("config", objConfig, New
Caching.CacheDependency("c:\mydir\config.xml"),
Web.Caching.Cache.NoAbsoluteExpiration,
Web.Caching.Cache.NoSlidingExpiration,
Web.Caching.CacheItemPriority.NotRemovable, Nothing)

It sticks and works. This is constantly reproducable, we have no resource
problems and are running on WinXP. Not sure if you have the same problem with
other dependency types.

- Manso
JohnWilley - 14 Mar 2006 16:15 GMT
Looks like you've proven the defaults for the various Cache.Insert
settings have changed between 1.1 and 2.0.  That's good to know.  One
thing that has helped us is using the callback function to write a log
message when the item is flushed from the cache.
markoh@community.nospam - 06 Apr 2006 13:38 GMT
Yep this definitely is the problem with Context.Cache object or web data
caching in general in ASP.NET.

It is easily reproducable using MSDN DynamicImage control (tutorial on MSDN
by Dino Esposito). That same control worked in 1.1 but now sometimes images
are retrieved from cache, sometimes the value in cache is null, which makes
the control useless because few images get loaded others don't or sometimes
none get loaded or all of them.

We would need official statement and solution from MS on this asap.

regards

> Ok, we've now figured out how to work around what seems to be an overly
> aggressive cache scavenging in ASP.NET 2.0. I'm not saying this is a bug
[quoted text clipped - 33 lines]
>
> - Manso
llong - 17 Apr 2006 19:27 GMT
Has there been anymore information on this problem? I am running into the
same issue?
mac - 25 May 2006 15:49 GMT
I am having the same problem of losing items in cache. I store object in
cache with time as 10 minutes. Upon postback i try to get the object from
cache but the object is gone. I changed from  HttpContext to HttpRuntime
cache but having the same problem. Is this something related to use
fileserver to run the website instead of IIS?

> Has there been anymore information on this problem? I am running into the
> same issue?
llong - 25 May 2006 16:19 GMT
I figured out my problem was the order I was creating the depedency with the
execution of the query. I was creating the dependency after I called the
query, this would give me strange results when I switched this around,
everything seemed to work fine.

This seems to work:
public override List<Category> GetCategories(string parentID, out
SqlCacheDependency dependency)
       {
           List<Category> categories = new List<Category>();

           SqlCacheDependency dep;

           SqlConnection connection = new SqlConnection(_connectionString);

           connection.Open();

           try
           {
               SqlCommand command = new
SqlCommand(CommandTexts.SelectByParentID, connection);

               dep = new SqlCacheDependency(command);

               command.Parameters.AddWithValue("@ParentID", parentID);

               SqlDataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnection);

               categories = this.CreateCategoryListFrom(reader);

           }
           finally
           {
               connection.Close();
           }
           dependency = dep;
           return categories;
       }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.