Forums / Developer / Clearing a specific cache-block ?

Clearing a specific cache-block ?

Author Message

Nabil Alimi

Friday 26 May 2006 2:13:26 pm

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}
{/foreach}
{/cache-block}

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.

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

Nabil Alimi

Tuesday 30 May 2006 1:07:39 am

Any idea ?

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

Nabil Alimi

Wednesday 07 June 2006 2:03:08 am

Hum... Hi there ?

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

Kristof Coomans

Wednesday 07 June 2006 3:01:27 am

Hi

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 :-)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Thomas Larsen

Wednesday 06 September 2006 7:53:00 am

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!

---------------------------------------------------------------------

Thomas Stage Larsen
System Developer

e : [email protected] | m: +45 26 12 47 61 | eZ systems A/S | w: www.ez.no

Kristian Hole

Wednesday 06 September 2006 4:07:24 pm

@Thomas:

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:
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_functions/miscellaneous/cache_block

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Thomas Larsen

Friday 08 September 2006 4:32:41 am

---------------------------------------------------------------------

Thomas Stage Larsen
System Developer

e : [email protected] | m: +45 26 12 47 61 | eZ systems A/S | w: www.ez.no

Kristian Hole

Sunday 10 September 2006 11:21:35 pm

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:

http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/data_and_information_extraction/ezhttp

http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/data_and_information_extraction/ezpreference

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?

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Thomas Larsen

Monday 11 September 2006 6:14:03 am

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?

---------------------------------------------------------------------

Thomas Stage Larsen
System Developer

e : [email protected] | m: +45 26 12 47 61 | eZ systems A/S | w: www.ez.no

Kristof Coomans

Monday 11 September 2006 6:41:11 am

Hello Thomas

You can fetch the current user with the user/current_user fetch function (<i>http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/user/fetch_functions/current_user</i>).

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristian Hole

Tuesday 12 September 2006 9:27:09 am

Did you get it working?

You did not tell me which template you were actually editing ;-)

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Bin LIU

Friday 08 February 2008 8:10:59 am

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";

and

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

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

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Maxime Thomas

Monday 28 February 2011 1:19:50 pm

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

eZContentCache::cleanup()

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

UPDATE

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) :

<code>var/ezflow_site/cache/template-block/3/8/0/380123145654.cache</code>

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.

Maxime Thomas
[email protected] | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Gaetano Giunta

Tuesday 01 March 2011 6:33:35 am

@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...

Principal Consultant International Business
Member of the Community Project Board

Maxime Thomas

Tuesday 01 March 2011 11:00:05 pm

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 :-D

Max

Maxime Thomas
[email protected] | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas