simple event cache question

I’m still a newbie but I finally have my app in 3.1 now and want to turn on some event based caches. I created a cache and see it in debug. My question is how do I add this event to a specific cache? I search and can’t find how.

trying something like

function someFunction(event,rc, cache=‘myCacheName’)
{
event.setview("someFunction);
}

Thanks.

Jonathan

You mean event caching right? The output of the event?

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Yes

http://wiki.coldbox.org/wiki/EventHandlers.cfm#Event_Caching

So I can’t place it in a named cache created in cacheBox?

the default cache for events and view caching is called “template”

So you would have to alter or create a named cached called “template” and then point it to whatever provider or configuration you like. As far as telling it this event into this named cache, not yet, 3.5

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

I’m using script and I have

function gameschedule(event,cache=“true”,cacheTimeout=“15”)

I look in the cache and don’t see it. I it the page several times. I did an fwreinit.

no, you have it wrong, metadata goes after the function in script

function gameschedule(event,rc,prc) cache=true cacheTimeout=15{

}

or use comment annotations

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Thanks. I do that. fwreinit, run the page, and check the cache and there are no events cached. I have plugins, handlers, and interceptors cached but no events. Do I need to inject cachebox in 3.1?

On the debugger make sure you switch to the template cache

The event cache works great but I only want it to cache my view not the entire layout. When I do this my users get confused because I show who is logged into the page and it shows the name of the person who created the cache. Am I doing something wrong? Is there a different way to cache just the view?

Thanks.

Well, you can just not cache the event and just cache the view: event.setView(name=”viewname”,cache=true);

However, I’d recommend using an interceptor and therefore caching the event for that user only.

Something as simple as:

component name=“cacheInterceptor” extends=“coldbox.system.interceptor”

{

void function OnRequestCapture( required any event, required struct interceptData)

{

var rc = arguments.event.getCollection();

rc.cacheKey = session.urltoken;

}

}

Essentially, that creates session specific caching…

Thanks Tom. I need to cache that page for everyone. It’s not a page required to be logged in, but they can be so the setView works for me.

Ok, so I thought that would work but this event accepts variables and since it’s caching the view it doesn’t act like the event cache where it considers each event with different variables a different cached object. So I’m back where I started.

Jonathon,

When I said “that user only”, I mean session-specific caching.

If you store any user information in the session, you could use that instead of the urltoken I used in my example (which is unique for every user).

So say you set session.userID=0 in you onSessionStart handler (for a public user), then you change that session.userID once someone logs in, every unlogged in (public) user will use the same public cache (for session.userID = 0), and every logged in user will see a cache specific for them only (session.userID = xxx).

OnRequestCapture interception point totally, totally rocks. My pps go like a train now :slight_smile:

Tom.

Alternatively, if you’re still not down with an interceptor, you can set a cacheSuffix for the view:

event.setView(name=”raa”,cache=true,cacheSuffix=”userID_#rc.userID#dogslike#rc.whatdodogslike#”);

Or if you want: event.setView(name=”raa”,cache=true,cacheSuffix=hash(serializeJSON([url,form])); (which will ensure view is cached basic on url/form vars

Tom.

If showing who is logged in is the only issue, I would bake a JavaScript variable into the view that updates the “whos logged in” text once the DOM is ready.

Aaron

Thanks the cachesuffix works great. I understand how to use this now.