eZ Community » Forums » Developer » Clearing a specific cache-block ?

Clearing a specific cache-block ?

Clearing a specific cache-block ?

Friday 26 May 2006 11:13:26 pm - 14 replies

Hi there,

Is there a way to clear a specific cache-block, knowing specified keys programmatically ?

Here's my problem.

I fetch content sorted by priority.

{cache-block keys=$some_stuff_here}
{def $my_objects=fetch( content , list , ... ) )}

{foreach $my_objects as $one_object}
{node_view_gui content_node=$one_object view=my_very_special_view}

But when the administrator changes priority, the cache-block isnt removed (which is normal). How could this be achieved... without removing the main cache-block ?
Also, I didn't found any function in cachemanager that cleared a specific cache-block.

Thanks for reading me.

Tuesday 30 May 2006 10:07:39 am

Any idea ?

Wednesday 07 June 2006 11:03:08 am

Hum... Hi there ?

Wednesday 07 June 2006 12:01:27 pm


Take a look at lib/eztemplate/classes/eztemplatecachefunction.php from line 304 to 347 (these line numbers are taken from trunk rev. 16200). You will have to do some var_dumps etc. to get to know how the cache file name is build.

Please let us know what the results are happy.gif Emoticon

Modified on Wednesday 07 June 2006 12:02:41 pm by Kristof Coomans

Wednesday 06 September 2006 4:53:00 pm

I will also like to now if it is possible to remove a specific cache-block, with a template function. My problem is that if I smart cache a list of elements, is not possible to change the offset variable after. Therefore I need to remove the cache for this specific page, but not for the whole site.

Looking forward to hear if anyone has a solution to this problem!

Thursday 07 September 2006 1:07:24 am


If you see in the source as Kristof specified, you see that getting the filename for the cacheblock is a bit tricky, since it depends on the position in the template file amongst other things.

If you are publishing elements in a specific part of the tree and want the cache-block, i suggest you use the "subtree=" parameter for the cacheblock.

Normally all cacheblocks are cleared when you publish an object, this can be limited with the mentioned subtree parameter, and also with the "ignore_content_expiry" parameter.

Buy correct use of these two settings i think you should be able to do what you want...

Take a look at the documentation here:

Friday 08 September 2006 1:32:41 pm

Modified on Friday 08 September 2006 1:35:10 pm by Thomas Larsen

Monday 11 September 2006 8:21:35 am

Hi Thomas,

As far as i understand, you need to use the "page-limit" as a key to your cache-block, and maybe in addition the user-id.

that would be something like
{cache-block keys=array( $node.path_string, ezhttp('SearchPageLimit','get' ),
$current_user.contentobject_id) }

This will ensure that a unique result for the cache block is generated for each searchpagelimit and user-id.

If you look in the admin-interface, the ezpreference is used instead of get parameters. Look in the following pages:



This will only work in the pagelayoutl. $current_user is only available there. And in the node-view templates (node/view*.tpl and overrides ) the viewcaching will add aditional caching which will affect your results.

Which templates are you actually adding this code?

Monday 11 September 2006 3:14:03 pm

Is not the pagelayout template I am working on in this case, so I can not use the $current_user.contentobject_id variable. Its also therefore I am using $node.path_string. Is there any other parameter I can use instead of $current_user?

Monday 11 September 2006 3:41:11 pm

Hello Thomas

You can fetch the current user with the user/current_user fetch function (<i>" title="http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/user/fetch_functions/current_user</i>blunk.gif Emoticon">http://ez.no/doc/ez_publish/techn...ch_functions/current_user</i>blunk.gif Emoticon.

Tuesday 12 September 2006 6:27:09 pm

Did you get it working?

You did not tell me which template you were actually editing blunk.gif Emoticon

Friday 08 February 2008 5:10:59 pm

Hi, did you find the solution ?

The path cache of cache-block with subtree is

static function calculateSubtreeCacheDir( $nodeID, $cacheFilename )
        $cacheDir = eZTemplateCacheBlock::subtreeCacheSubDirForNode( $nodeID );
        $cacheDir .= '/' . $cacheFilename[0] . '/' . $cacheFilename[1] . '/' . $cacheFilename[2];

        return $cacheDir;

so we can find it by $nodeID of subtree.

But for the cache-block without subtree (with keys), the path is

 $filename = eZSys::ezcrc32( $keyString ) . ".cache";


$keyArray = array( $keys, $placementString, $accessName );

but what is the $keys, $placementString ? i can't find it. other idea ?

Monday 28 February 2011 10:19:50 pm

I found a function that is useful to clean cache when you know the keys :


Seems to be an old stuff but has the Cluster support.


This function will work only if you know the path or correct keys of your cache.

With some tests, I've found what keys are expected by this function :

  1. The key string : it's the crc32 of a serilazed version of your array of keys.
  2. Subtree expiry : can be null
  3. ttl : can be null.

As the generated key string was different from what I was computing in #1, I've looked under the eztemplatefunction.php and more precisely under the templateNodeTransformation function.

It appears that the keys array is composed of :

  1. Array of keys
  2. Placement : it's a string defined by the start (line / column) and the end (start / column) of the cache block inside the calling template. It looks like 83_42_122_37_extension/.../design/standard/templates/name_of_the_template.tpl.
  3. Siteaccess.

Then this is processed to match the crc32(serialize keys array) :


You may notice that the folders (3/8/0) are the extract of the beginning of the filename.

So, the only way to find the cache generated is to know where it is (if not linked to a node_id).

I will follow the track to find the placement that is hardcoded inside the PHP cache, maybe with a small regexp we can reach the placement.

Modified on Tuesday 01 March 2011 7:49:08 am by Maxime Thomas

Tuesday 01 March 2011 3:33:35 pm

@Maxime if you search hard enough in wit, you'll find there is a feature request already to alter the path of the generated cache block files so that without knowing the keys in use but only the original template file and line/col of the block operator you can delete all of its cached files...

Wednesday 02 March 2011 8:00:05 am

Hi Gaetano,

Actually, it does not match what I want to do. I have the keys (user_id and other things) and I know the template. I just want to clear the cache for this combination.

The use context is a classic Ajax script that will do some back office actions in front and when the user refreshes the page, cache has to be refreshed.

If you have a good solution for this one, I'm taking it big-smile.gif Emoticon



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

36 542 Users on board!

Forums menu

Proudly Developed with from