Forums / Setup & design / query string stuck in view cache

query string stuck in view cache

Author Message

*- pike

Wednesday 12 August 2009 7:34:25 am

Hi

the standard node view caching does not seem to take query strings in to account. for example, if I've written a (node) template that responds to

/node/view/full/3256?showimages=true

by showing, or hiding, the images, it works .. the first time only. if someone at any later time requests

/node/view/full/3256?showimages=false

the cached output will be returned - without images.

I didnt think about this when the site was in development, and all caches where off :-/

I'm pretty stuck here. Does anyone know where to change that caching behaviour .. or any other easy workaround ?

thanks,
*-pike

---------------
The class eZContentObjectTreeNode does.

*- pike

Wednesday 12 August 2009 7:42:34 am

So what *exactly* should

{set-block scope=root variable=cache_ttl}0{/set-block}

do ? should it
- a) not retrieve the content from cache; or
- b) not store the generated content in cache; or
- c) expire any existing cached content; or
- d) regenerate existing cached content
or any combination of those ?

curious
*-pike

---------------
The class eZContentObjectTreeNode does.

André R.

Wednesday 12 August 2009 7:50:39 am

Use view parameters, they are native to view cache and eZ Publish and are better for SEO.

The url would look like:

/content/view/full/3256/(showimages)/true

or if you use nice urls it could look like(depending on the url of course):

/Pictures/Trip-to-London/(showimages)/true

In your node template you'll be able to access it like:

{def $show_images = first_set( $view_parameters.showimages, false())}

Some view parameters are always set (in node templates, aka content/view), and don't need the first_set syntax:
offset, year, month, day and namefilter

EDIT: as for your second question, cache_ttl=0 tells the system to not store the cache. Normally it tells the system how many seconds the cache should be considered valid (unless expired by the cache system in the mean time). Default is -1, meaning it only expires when the cache system expires it, normally when you edit the content or related content as defined in viewcache.ini.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

*- pike

Wednesday 12 August 2009 9:29:43 am

>Use view parameters, they are native to view cache and eZ Publish and are better for SEO.

I was trying to avoid them. They are only 'better for SEO' if they contain information that is relevant for the SE (like 'offset'). In cases where the query string is used for non-informational purposes .. like "?number_of_times_tried=3", Google doesnt need to know. And, I think they're very ugly.

In my particular case, google shouldnt even get to the page, ever.

{set-block scope="global" variable="cache_ttl"}0{/set-block}

seems to not-store-and-not-retrieve the cache, so that seems to work for me. question remains if that would expire any stored cache too .. which is unnecessary overhead in my case, but still useful to know.

[EDIT] that was wrong. cache_ttl=0 does not store the cache, but if it was already stored, the template never gets parsed again, and the cached version will be retrieved.

*-pike

---------------
The class eZContentObjectTreeNode does.

André R.

Wednesday 12 August 2009 1:12:47 pm

> question remains if that would expire any stored cache to

No, it will not expire any stored cache. It will create a cache lock(avoids race conditions), generate content, see that template returned cache_ttl=0, and delete the cache lock.
If this is for specific node id('s), then you can get a slightly more efficient(avoid the cache locking) overhead by using site.ini[ContentSettings]ViewCacheTweaks[]

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

*- pike

Friday 18 September 2009 10:48:13 am

Thanks for your clear response. In fact, in find it doesnt seem to work, only in some specific conditions, but thats exactly what you're saying I think:

 cache_ttl=0 tells the system to not store the cache.

That's all fine, but if the cache *is* already stored, then most likely ezpublish is not going to parse a template again to see if it should retrieve the cached version of the node's view :-) That would defeat the purpose So

{if $somecondition}
   {set-block scope="global" variable="cache_ttl"}0{/set-block}
{/if}

would only work as long as $somecondition remains true. if anyone ever views the page with $somecondition false, cache is stored and the template code is never looked at again.

That is just a guess. Can anyone confirm this ?

curious,
*-pike

---------------
The class eZContentObjectTreeNode does.

André R.

Friday 18 September 2009 12:54:38 pm

Yes, you can not disable view cache conditional unless its a condition that is used as part of cache name hash, like user access rules, node id, class id, view params, user perferences, siteaccess name or shop data (orders).

Actually, the code is only about 30-40 lines, so just have a quicklook yourself to see how you can make it work to your need:
http://pubsvn.ez.no/nextgen/trunk/kernel/classes/eznodeviewfunctions.php

Search for "n generateViewCacheFile".

Some explanations on parts of the code that are not commented

// uses site.ini when no parameters are passed to eZINI
$ini = eZINI::instance();
..
// relative www path to index.php(if you have index.php in url)
// including sub folder eZ Publish might be in
$cacheHashArray[] = eZSys::indexFile();

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

*- pike

Thursday 24 September 2009 5:16:41 am

Hi

brilliant !

from http://pubsvn.ez.no/nextgen/trunk/kernel/classes/eznodeviewfunctions.php

$cacheFile = $nodeID . '-' . md5( implode( '-', $cacheHashArray ) ) . '.cache';

thats clear allright. now, if i wanted to add, say, the GET querystring to the cacheHashArray, would it be enough to do it only there ?

I would expect to have to add the same logic to, for example, ezNodeViewFunctions::contentViewRetrieve. Strangely enough, I dont see these methods being referenced from much in doxygen. Is there a flowchart of the process somewhere .. guess not ? :-)

I think the question is - do you think its feasible to 'patch' this behaviour, and if so, where do you think patches would be needed ?

thanks a zillion!
*-pike

---------------
The class eZContentObjectTreeNode does.

*- pike

Friday 25 September 2009 5:58:24 am

Hi

And *again*, I read your post too quick. You offer an bright solution right between your dense vulcan logic there. I am mere human, please, bear with me.

Yes, you can not disable view cache conditional unless its a condition that is used as part of cache name hash, like (...), node id, class id, view params ...

So, if I post a form to a url like

/content/view/full43/(dontcache)/true?color=blue

I can catch the caching mech with

{if $view_parameters.dontcache}
	{set-block scope="global" variable="cache_ttl"}0{/set-block}
{/if}

This will never store the cache, and it will never retrieve a cache, because (dontcache) is a view parameter and hence *would be* part of the cache key (but will never be, because of the template code). Tested, works.

Now, theoretically, the question still remains interesting. Would eznodeviewfunctions::generateViewCacheFile be the only place needed to patch functionality for adding other keys (like get parameters) to the viewcache ?

thanks,
*-pike

 

---------------
The class eZContentObjectTreeNode does.