Forums / Setup & design / Smart View Cache mechanism

Smart View Cache mechanism

Author Message

laurent le cadet

Wednesday 29 August 2007 8:15:41 am

Hi,

I read doc. about the smart view cache but can't really do what I need, understand the way it works :(

I have a parent class "Company" with children "Product".

In "Company" I have a date attribute "limitdate".
It's use to show or not (compared to the currentdate), a part of the "Product" objects.

When I edit a "Company" and change the "limitdate", the children content view is not clean.

I tryed this :

[product]
DependentClassIdentifier[]
DependentClassIdentifier[]=company
ClearCacheMethod[]
ClearCacheMethod[]=relating

in viewcache.ini but no success.

Thanks for your help.

Laurent

André R.

Wednesday 29 August 2007 11:14:34 am

Viewcache does not clear cache of children.
But it should be possible to specify that, so create a enhancement issue for adding ClearCacheMethod[]=children, this should of course just clear direct children and not the whole subtree.

In your case you might want to set cache_ttl in your product templates to clear cache every hour or something.

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

laurent le cadet

Wednesday 29 August 2007 11:46:07 pm

André,

What you propose is what I need = just clear the content cache of direct children.

create a enhancement issue for adding ClearCacheMethod[]=children

So I tryed this as I don't really know what you mean:

[product]
DependentClassIdentifier[]
DependentClassIdentifier[]=company
ClearCacheMethod[]
ClearCacheMethod[]=children

But it doesn't seems to be enough.

Could you tell me more.

Thanks.

Laurent

Heath

Thursday 30 August 2007 12:10:05 am

Hello Laurent

I think André, was asking you to please create a new enhancement issue using eZ's issue tracking system, http://issues.ez.no/ProjectSummary.php?ProjectId=3

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

kracker (the)

Thursday 30 August 2007 12:11:13 am

It sounds like a good idea, please do create the issue :)

Cheers,
//kracker

We still chuckle at the story behind your funny photo!

<i>Kottonmouth Kings : Set Me Free ...</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

laurent le cadet

Thursday 30 August 2007 12:22:49 am

Thanks to the Nabuchodonosor crew for pointing me the direction.
But it doens't seems to be so easy.

Laurent

Bruce Morrison

Thursday 30 August 2007 12:37:53 am

Hi Laurent

Can you post the template code for the Company & Product objects? I suspect that the Smart View Cache is not what you need to use in this case.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

laurent le cadet

Thursday 30 August 2007 12:55:10 am

Hi Bruce,

So here is the company.tpl

{def $currentimestamp = currentdate()
     $debuttimestamp  = $node.object.data_map.debut_abonnement.data_int
	 $fintimestamp    = $node.object.data_map.fin_abonnement.data_int
	 $approbation     = $node.object.data_map.approbation.data_int
	 $children        = fetch('content','list',hash( parent_node_id, $node.node_id,
						sort_by, $node.sort_array ) )
     $children_count = $children|count()}
	 
	<div class="content-view-full">
	<div class="class-entreprise">
	{if $approbation}

	<h1>{$node.data_map.societe.content|wash()}</h1>

	<div class="logo">
		{attribute_view_gui attribute=$node.data_map.logo image_class=medium alignment=right}
	</div>
	
	<div class="break"></div>
	
	<div class="adresse">
		<ul>
		<li>{attribute_view_gui attribute=$node.data_map.adresse}</li>
		<li>{attribute_view_gui attribute=$node.data_map.code_postal}</li>
		<li>{attribute_view_gui attribute=$node.data_map.ville}</li>
		<li>{attribute_view_gui attribute=$node.data_map.pays}</li>
		<li>{attribute_view_gui attribute=$node.data_map.telephone}</li>
		<li>{attribute_view_gui attribute=$node.data_map.fax}</li>
		<li>{attribute_view_gui attribute=$node.data_map.site_internet}</li>
		</ul>
	</div>
	
	<div class="activite">{attribute_view_gui attribute=$node.data_map.activite_entreprise} ({attribute_view_gui attribute=$node.data_map.profil})</div>

	{if $node.object.can_edit}
		
		<ul>
		<li>Effectif entreprise : {attribute_view_gui attribute=$node.data_map.effectif_entreprise}</li>
		<li>Avantages abonnement : {attribute_view_gui attribute=$node.data_map.avantages_abonnement}</li>
		</ul>
		
		<h2>Votre abonnement</h2>
		<p>Vous êtes inscrit sur zoneindustrie.com depuis le {$debuttimestamp|l10n(date)}.</p>
		
		<p>
		{if $node.data_map.fin_abonnement.content|not()}
		{if gt(sum($debuttimestamp,7776000),$currentimestamp)}
			Vous êtes actuellement en utilisation gratuite et votre entreprise ainsi que vos produits sont visibles jusqu'au {sum($debuttimestamp,7776000)|l10n(date)}
		{/if}
		{/if}
		
		{if and($node.data_map.fin_abonnement.content, gt($fintimestamp,$currentimestamp))}
			Vous êtes actuellement en abonnement payant et votre entreprise ainsi que vos produits sont visibles intégralement jusqu'au {$fintimestamp|l10n(date)}.
		{/if}
		
		{if and($node.data_map.fin_abonnement.content, lt($fintimestamp,$currentimestamp), gt(sum($fintimestamp,7776000),$currentimestamp))}
			Vous n'êtes plus en abonnement payant et seul votre entreprise et vos 3 derniers produits sont visibles jusqu'au {sum($fintimestamp,7776000)|l10n(date)}.
		{/if}
		
		{if and($node.data_map.fin_abonnement.content, gt(sub($currentimestamp,7776000),$fintimestamp))}
			Votre date d'abonnement est dépassée et seule votre entreprise est présente sur zoneindustrie.com.<br>
			Vos produits sont actuellement masqués.<br>
			<a href="#">Renouveler votre abonnement</a>
		{/if}
		</p>
		
	{else}
		{if gt($fintimestamp,$currentimestamp)}
		<div class="content-view-children-three">
			{section var=child loop=$children}
				{node_view_gui view='line' content_node=$child}
			{delimiter modulo=1}
		</div>
		<div class="content-view-children-three">
		{/delimiter}
		{/section}
		</div>
		<div class="break"></div>
		{/if}
		<div class="attribute-tipafriend">
			<p>
				<a href={concat('/content/tipafriend/',$node.node_id)|ezurl}>{"Tip a friend"|i18n("design/base")}</a>
			</p>
		</div>
	{/if}
	
	{else}{* APPROBATION *}
		Finalisation de l'inscription de cette entreprise en cours.
	{/if}
    </div>
</div>

Tha's the

$fintimestamp = $node.object.data_map.fin_abonnement.data_int

I refer to while showing the children of the company node, like this in product.tpl:

{def $currentimestamp = currentdate()
     $objectimestamp  = $node.object.data_map.date_marche.data_int
	 $parentimestamp  = $node.parent.data_map.fin_abonnement.data_int
	 $email           = $node.contentobject_version_object.creator.data_map.compte_utilisateur.content.email}
	 
	<div class="content-view-full">
	<div class="class-produit">

	<h1>{$node.data_map.nom.content|wash()}</h1>
	{if gt($objectimestamp, sub($currentimestamp, 7776000))}
	<div class="new">
		<img src={"images/icon_nouveaute.gif"|ezdesign} height="11" width="48" title="Nouveauté" alt="Nouveauté" />
	</div>
	{/if}

	{attribute_view_gui attribute=$node.data_map.image image_class=medium alignment=right}
	
	{if $node.data_map.marque.content}
		{attribute_view_gui attribute=$node.data_map.marque}
	{/if}
	
	{attribute_view_gui attribute=$node.data_map.presentation_produit}
	
	{if ge($parentimestamp,$currentimestamp)}
	
		{if $node.data_map.descriptif_detaille.content}
			{attribute_view_gui attribute=$node.data_map.descriptif_detaille}
		{/if}
	
		{if $node.data_map.documentation.content}
			{attribute_view_gui attribute=$node.data_map.documentation}
		{/if}
	
	<div class="break"></div>
	
	<form method="get" action="/contact">
		<input type="hidden" name="produit" value="{$node.data_map.nom.content}" />
		<input type="hidden" name="email" value="{$email}" />
		<input type="image" class="btn-info-produit" src={"1x1.gif"|ezimage} />
	</form>
		
	{/if}

	
	<div class="break"></div>

		<div class="attribute-tipafriend">
			<p>
				<a href={concat('/content/tipafriend/',$node.node_id)|ezurl}>{"Tip a friend"|i18n("design/base")}</a>
			</p>
		</div>


    </div>
</div>

In that template :

$parentimestamp = $node.parent.data_map.fin_abonnement.data_int

{if ge($parentimestamp,$currentimestamp)}...{/if}

I know this kind of comparison is a bit out of the normal content view.

Is that clear enough?

Laurent

Bruce Morrison

Thursday 30 August 2007 4:12:12 pm

Hi Laurent

The easiest option is ot follow Andrés suggestion of setting cache_ttl. You may be able to do something with a cache-block and the subtree_expiry parameter to clear the caches when the parent is republished. (you'd have to disable the view cache for this - cache_ttl = 0)

Another option is to create a workflow that clears the child node caches on publishing of the parent.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

laurent le cadet

Thursday 30 August 2007 11:43:45 pm

yes Bruce,

I think too that the cache-block is the best solution, but I'm not really a cache-block killer and I know a bad templating can be a real performance disaster.

What I know is that we can use the ttl for the content view cache.
So if I follow your hint, it should be first like this (in product.tpl) :

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

...and then something more?

{cache-block subtree_expiry=$node.parent.node_id}
my product template code.
{/cache-block}

Please, correct me if I'm wrong.

Laurent

André R.

Friday 31 August 2007 1:11:25 am

The most optimized way should be:

{cache-block subtree_expiry=concat('content/view/full/', $node.parent_node_id )}
my product template code.
{/cache-block}

BUT! If you have lots of products and they change often, all products cache will be cleared, so it might be better to do something like:

{def $parentimestamp = $node.parent.data_map.fin_abonnement.data_int}
{cache-block keys=$parentimestamp subtree_expiry=concat('content/view/full/', $node.node_id )}
 {def $currentimestamp = currentdate()
  $objectimestamp = $node.data_map.date_marche.data_int
  $email          = $node.contentobject_version_object.creator.data_map.compte_utilisateur.content.email}
  my product template code.
{/cache-block}         

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

laurent le cadet

Friday 31 August 2007 2:46:56 am

André,

Fine tunning :

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

{def $parentimestamp  = $node.parent.data_map.fin_abonnement.data_int}
{cache-block keys=$parentimestamp subtree_expiry=concat('content/view/full/', $node.node_id )}
{def $currentimestamp = currentdate()
	 $objectimestamp  = $node.object.data_map.date_marche.data_int
	 $email           = $node.contentobject_version_object.creator.data_map.compte_utilisateur.content.email}
	 
.... Additionnal template code here ....

{/cache-block}

{set-block scope=root variable=cache_ttl}0{/set-block} is necessary first to kill the ttl ?

Laurent

laurent le cadet

Friday 31 August 2007 3:34:59 am

I tested it that way and it seems to have the right behavior.

Thanks to everybody.

Laurent

PS : Template cache-block optimization is a very important part for "complex" content architecture. It should be nice to have a more consitent reference document.

Vincent Lepot

Monday 03 September 2007 11:20:08 am

I'm coming back on André suggestion.

I think that the Smart cache clear part of the code should be extended by user code (I mean in an extension surdir for example).

I had a similar problem where cache-block can't help me (I wanted to invalidate cache of objects related to objects related to my content... ok, it seems stupid, but in my context, it was necessary). Moreover, keeping content view cache is better to keep correct performance (cache-block use suppose node view template execution every time you call the page).

Do you think it's a stupid idea, or shall I create an enhancement request in this way ?

Bruce Morrison

Monday 03 September 2007 4:54:20 pm

Hi Vincent

There are already a number of options to clear caches of related objects/nodes. I believed there where changs in version 3.9. How are the objects related that you had to clear the cache for?

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Vincent Lepot

Monday 24 September 2007 6:26:37 am

Hi Bruce,

My objects are related to an object related to the one I publish.

I can't deal with such cache invalidations with neither smart cache clear nor cache-block tags.

Regards
Vince