Using Cache expiration to invoke Delegates...

B

Beren

Hello

I'm trying to use Cache expiration and its callback feature to easily
add automated tasks programmatically. The task should be run when the
Cache object expired

The problem I'm facing is that some tasks will only be expiring (thus
running) in 2 months.
What if the server needs to reboot? Will the Cache be lost (and with
it all my Tasks) ?

If so, how could I save the Cache Objects of choice (my Tasks) exactly
as they are. These Tasks contain a Delegate holding the address of the
method to run, so I doubt I can serialize this to XML or to a DB...

All suggestions and advice are very welcome!


Beren.
 
M

Mr Newbie

Why dont you store the tasks in an XML or other data storage and poll this
on a regular basis instead of trying to implement what seems to me ( and I
am probably quite wrong ) to be an overly complicated method of deciding
when to run a task ?

If you must serialize the Objects in cache, cant you add the <Serialize>
Attribute to them and then store them ?

All in all this sounds like a precarious way of designing a system. Having
said that I dont really know the ins and outs of why you have architected it
this way so I am really in no position to judge.

Regards Mr N
 
K

Kevin Spencer

Hi Beren,

First, yes, your Cache isn't nearly as safe a container as you might think.
In fact, it will be dumped every time the Application shuts down, which will
happen any time there are no requests from anyone for 20 minutes. You can
extend the lifetime of the Application just like extending the lifetime of
the Session, but that only reduces the issue, and does not elimate it.

So, the first thing you need to do is determine how critical these tasks
are. What happens if they don't run? If they are indeed critical, you need a
different solution than Cache. Any solution that is reliable would involve
serializing data to the disk, whether this is via XML, binary files,
database, or possibly Windows Messaging services.

That also means that you're going to have to remodel your tasks not to use
delegates. If you use Windows Messaging services, or the soon-to-be-released
Indigo Services, you get both reliability of data, plus guaranteed delivery
of the message. It is important to note that delegates are not the only way
to determine what method is executed. Any message can include some sort of
information about what should be done in response to the message.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
B

Beren

Thank you for the replies,

I've been thinking this over and right now I'm planning to make this
work via Reflection. In my Task object I could store the Assembly,
ClassName and MethodName I want to invoke. This way no Delegates are
needed and I can serialize this information easily to XML.
Expiry check would have to happen with a Timer that regulary checks
this dataset, no Cache expiry dates anymore...

To stay somewhat faithful to the title of this post: Why not cache the
XML as a dependency... :)

Kevin, your informative post boiled another question up for me
concerning the Cache, but perhaps this belongs in the Caching group...

So I decide to cache the XML (dataset) with my reflection data for
faster access. When the Cache is dumped after 20 minutes as you say,
will the CacheCallback method still be called? That might prove to be
disastrous. And finally -to be all safe- I guess there's no other
option but to re-Cache the tasks dataset in Application_Start.
These tasks are one of the core parts from the system.


Thanks alot,

Beren.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top