[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

2.0 Cache weirdness found (and possibly a solution

Manso

3/6/2006 9:37:00 PM

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

5 Answers

JohnWilley

3/14/2006 3:15:00 PM

0

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

4/6/2006 12:39:00 PM

0

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


"Manso" <Manso@discussions.microsoft.com> wrote in message
news:21114551-F902-42AD-AC5B-C3DF5D941D95@microsoft.com...
> 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
>


llong

4/17/2006 6:27:00 PM

0

Has there been anymore information on this problem? I am running into the
same issue?

Mac

5/25/2006 2:49:00 PM

0

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?

"llong" wrote:

> Has there been anymore information on this problem? I am running into the
> same issue?

llong

5/25/2006 3:19:00 PM

0

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;
}