mostlylucid

scott galloway's personal blog...
posts - 916, comments - 758, trackbacks - 11

My Links

News

Archives

Post Categories

Misc. Coding

Update of the previous post...had to tag strip for syndication...

I'm trying to simulate the .NET 2.0 Database Cache Dependency stuff (well kind of, WAY simpler obviously). What I'm doing is running a little timer class as a static property of my global.asax.cs file...like so:

public static TimerClass timr = new TimerClass();

 My actual timer class thing is really simple, it just adds items to a queue on each tick; in the actual app this will fire a simple stored procedure and only add certain items if the item has been updated. This is all really to get round requiring a context to update some stuff in the cache...this way I can do it 'offline'

using System;

using System.Timers;>


namespace CacheTimerTest

{

            ///

            /// Summary description for TimerClass.

            ///

            public class TimerClass

            {

                        public TimerClass()

                        {

                                    Timer timer = new Timer();

                                    timer.Enabled=true;

                                    timer.Interval=5000;

                                    timer.Start();

                                    timer.Elapsed +=new ElapsedEventHandler(timer_Elapsed);

                        }

 

                        private void timer_Elapsed(object sender, ElapsedEventArgs e)

                        {

                                    if(!Global.qu.Contains("update1"))

                                    Global.qu.Enqueue("update1");

                        }

            }

}

So here's my question, can anyone think of a reason why this won't work reliably, as I say, I have a nagging feeling it won't but for the life of me I can't think why...

 

Print | posted on Friday, May 14, 2004 8:58 PM |

Feedback

Gravatar

# re: Update of the previous post...had to tag strip for syndication...

The only issue is, surely, that it's still not true cache dependency - there is the potential of having updated/deleted information in the database that isn't re-cached until the next tick of the timer.

True, the timer can be set to a very low interval, but this could cause the problem of using dirty data...depending on how the cache was being used of course!

Effectively what you've written is a time based cache dependecy that only invalidates the cache if the data has changed. Yes, it means a reduction in the number of times the cache is recreated (and hence reduces the calls to the database), but is it worth it?? Then again, I know how you love to maximise application performance, so I guess the answer is yes!! Check out &lt;A href=&quot;<a target="_new" href="http://aspalliance.com/251&quot;&gt;this">http://aspalliance.com/251&quot;&gt;this</a> article&lt;/a&gt; I was reading just before i saw your post...

Michael
5/14/2004 9:00 PM | Michael Falconer
Gravatar

# re: Update of the previous post...had to tag strip for syndication...

It actually is worth it in the case of the app i designed this for (and which currently uses it - The Microsoft Education Community http://www.theeducationcommunity.com). In this instance, I have most of the content cached and it's only updated when some item is added, modified or deleted, this is done through a simple invalidation of a cache entry and requiring the control reloads it's content from the DB. Problem was that we had 2 servers and this invalidation only happened on 1 server - so the second server was out of sync and could theoretically remain so indefinetly. This little timer solved the problem by periodically 'pinging' the db (actually doing a simple call on an SP which returns a small result set containing what needs to be updated). On the BeginRequest event in Application, I can then invalidate the appropriate cach keys (the SP takes account of the server name - so doesn't get confused by it's own entries). Seems to work pretty well...and the occasional DB ping (which happens on a separate, non-user thread) has practically no performance hit...
5/20/2004 1:33 PM | Scott Galloway
Comments have been closed on this topic.

Powered by: