Expiring Cache using Multiple Conditions

Topics: Writing modules
Feb 25, 2011 at 5:41 PM

I'd like to setup my caching where I'm monitoring several cache invalidators. So, I'd like to add multiple IVolatileTokens to the action. One may be a clock that is set to expire every hour. The other may be a signal that is tripped when the settings for a module change.

It doesn't look like there's a way to add multiple conditions. Is there?

Coordinator
Feb 25, 2011 at 5:45 PM

In the lambda you can add multiple calls to ctx.Monitor()

Feb 25, 2011 at 5:49 PM

Like so?

ctx =>
{ 
    ctx.Monitor(_signals.When("MyModule.Changed"));
    ctx.Monitor(_clock.When(TimeSpan.FromMinutes(5)));
    return BuildObject(part);
});
Coordinator
Feb 25, 2011 at 8:08 PM

Exactly, too lazy to provide an example, thank you.

Feb 25, 2011 at 9:29 PM

Didn't think it would work which is why I didn't try. I'll check it out though after I get my module working. :|

Coordinator
Feb 28, 2011 at 11:23 PM

It's even more powerful than that: it cascades. If your Lambda is using a cached object (explicitly or implicitly through some function call), the "invalidators" of the deeper objects will bubble up and invalidate the outermost ones.

Mar 1, 2011 at 12:14 AM
Sounds interesting. Thanks for the explanation.
Jason
From: [email removed]
Sent: Monday, February 28, 2011 7:23 PM
To: [email removed]
Subject: Re: Expiring Cache using Multiple Conditions [orchard:247605]

From: bertrandleroy

It's even more powerful than that: it cascades. If your Lambda is using a cached object (explicitly or implicitly through some function call), the "invalidators" of the deeper objects will bubble up and invalidate the outermost ones.

May 5, 2011 at 7:16 AM

Hi jqaylord, did you manage to get this working. I am working on a scheduler type function where I need an event to fire hourly / daily / weekly / monthly etc. to send notifications or perform various task etc. Not sure how to go about doing this though so if you would be so kind to share some code to include in my module I will be eternally greatful.

May 5, 2011 at 9:31 AM

@Garpo you don't really want the cache feature, you just need background tasks.

May 5, 2011 at 10:01 AM

Makes sense, still not sure how to implement this in my module though...