Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Cache Callback Problem - it doesn't happen


Cache Callback Problem - it doesn't happen

Reply
  #1 (permalink)  
Old 12-24-04, 07:54 AM
titch_stewart titch_stewart is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Cache Callback Problem - it doesn't happen

Apologies for the long post, this is driving me up the wall, I'm sure it's something pretty simple but can't put my finger on it and can't find any help on the web.

I'm trying to implement a Callback for an item I put into the Cache. I have tried the following:

1] Putting the code into Global.asax like as per these examples:
http://www.eggheadcafe.com/articles/20030418.asp
http://www.eggheadcafe.com/articles/20030416.asp

2] Putting the above code into a web page to see whether it will work
3] Creating a seperate object (see code below) and creating and using that in my web page Page_Load method:

public class mcCacheExpire
{
//
// This holds a reference to the method to call back
//
private CacheItemRemovedCallback OnRemove = null;

public mcCacheExpire()
{
OnRemove += new CacheItemRemovedCallback( CacheDumped );
}

public void AddCacheItem( int i, int iMinutes )
{
// Add to the cache with key value "A"
System.Web.HttpRuntime.Cache.Insert( "A", i, null,
// DateTime.Now.AddMinutes( iMinutes ), System.Web.Caching.Cache.NoSlidingExpiration,
DateTime.Now.AddMinutes( 10 ), TimeSpan.Zero,
CacheItemPriority.Normal, OnRemove );

//
// Debug
//
easier.writeToFile( "Session_End.txt", "ADDED A CACHE ITEM FOR: " + i + " at: " );
}

public void CacheDumped(string k, object v, CacheItemRemovedReason r)
{
easier.writeToFile( "Session_End.txt", "DUMPED THE FOLLOWING CACHE ITEM: " + k + ", FOR OBJECT: " + v.ToString() + ", FOR THE FOLLOWING REASON: " + r.ToString() );
}
}

The above code was amending from this site:

http://aspalliance.com/69

Basically the Callback is never called (actually it worked for a couple of times) when timing out. If I call Cache.Remove ( cachekey ) the Callback is called.

So basically why wouldn't the Callback be called? Is there a server setting or web.config setting that has to be set when using the Cache to store data? Is the object going out of scope? If so, how should I implement so it doesn't go out of scope, etc?

I asked my admin about this and they said:

"The application should be ok on your site as it is isolated from all other apps on the server. Do you think there may be other settings in the app pool which should help? Most of the time they are left as default with the settings, so I would imagine it would be ok as it is." - any thoughts?

I can add more code if necessary.

Also my Session_End function in Global.asax is never called even though Session_Start is - why would this be? My web.config looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
<sessionState mode="InProc"
cookieless="false"
timeout="20"/>
</system.web>
</configuration>

Thanks for your help,

Titch
Reply With Quote
  #2 (permalink)  
Old 12-27-04, 07:09 PM
titch_stewart titch_stewart is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Fix

This is what happens if you have more than one global.asax file. I had one in my root dir and my app dir, deleting the one in the app dir made it all work fantastically - exactly what it said in the url ;-)

I'm taking it that you can only have on global.asax file then???

btw - it solves the Session_End function not being called as well.

Double bonus

Cheers,

Titch
Reply With Quote
  #3 (permalink)  
Old 12-30-04, 04:16 PM
titch_stewart titch_stewart is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Basically there was 2 Global.asax files and it was getting confused by them.

Cheers,

Titch
Reply With Quote
  #4 (permalink)  
Old 12-30-04, 04:18 PM
titch_stewart titch_stewart is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry should have said - one in the wwwroot dir and one in my App dir.

My ISP had a different setting for my App than I was expecting as well.

Cheers,

Titch
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Count problem kasic ASP.NET 1 10-20-04 12:23 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM
an unusual problem.... fabulosas10 PHP 0 07-16-04 02:03 AM
Where are MySQL cache files? darkfreak PHP 4 06-21-04 12:30 AM
IE redraw problem in iframes bsilby JavaScript 2 05-31-04 03:57 PM


All times are GMT -5. The time now is 01:00 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.