custom caching from within an extension

custom caching from within an extension

Thursday 11 March 2010 10:28:26 am - 4 replies

Author Message

Gaetano Giunta

Thursday 11 March 2010 1:04:43 pm

- create a template fetch function that does the ws calls

- put cache blocks around those calls in the template

Principal Consultant International Business
Member of the Community Project Board

Matthew Carroll

Thursday 11 March 2010 2:09:52 pm

Thanks! That was the nudge I needed to see the problem from a new angle.

Currently it does all three external fetches within the one operator function, but if I extract some of the logic out to the ez template instead, and put the second and third lookups in a separate function, it will be more efficient overall.

I was trying to imagine taking the caching into the php of the extension, when what I need to do is bring a small portion of the extension logic out to the ez template. I just wasn't thinking about the problem the right way (isn't that always the challenge!)

http://carroll.org.uk

Matthew Carroll

Thursday 11 March 2010 7:48:41 pm

Unfortunately the approach I thought would work doesn't seem to.

I took out the second two external website lookups and put them into a template fetch function, but I need to be able to access the result of that fetch as a variable later on. If I do this:

{cache-block expiry=86400}
{def $mylist=fetch( 'mplookup', 'list', hash())}
{/cache-block}

...it doesn't work the second time, as the variable $mylist doesn't exist once that block is cached. Does that make sense? I want to cache the result of the fetch, but still be able to access the variable next time that template is used (with a different view parameter). Am I missing something obvious here?

Thanks
Matthew

http://carroll.org.uk

Gaetano Giunta

Friday 12 March 2010 12:29:13 am

No, it is the way cache-blocks work: the actual html is stored in the file on disk, no template-level variable.

Workarounds:

- move the display of the results within the cache-block (nb: cache-blocks can be nested)

- let the cache-block save data into a js variable and use it later down the page for display

Principal Consultant International Business
Member of the Community Project Board

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.