Forums / General / Add to bookmarks and viewcache

Add to bookmarks and viewcache

Author Message

Carlos Revillo

Tuesday 11 November 2008 12:49:52 pm

Hi.

We're working in a community site and we want "add to bookmark" links in every content.

let's suppose we have articles and registered users could add this article (node) to their favourite links off the site.

We have built a small extension for adding and removing from bookmarks. This extension uses

eZContentBrowseBookmark::createNew($userID,$nodeID,$nodeName);

for adding and

$bookmark=eZContentBrowseBookmark::fetch($bookmarkID);
$bookmark->remove();

for deleting.

Ideally, when user use add to favourite link, bookmark should be added and the user will be redirected to the same article

As user has added the node to bookmarks, the "add to bookmark" link needs to be changed by a "remove from bookmarks" link.

But i don't really know if this is possible having viewcache enabled and not having

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

in the very top of the template.

I mean. I would like to cache everything in the node/view/full/article.tpl template except the part for those add and remove from bookmarks link.

Any ideas? Thank you.

André R.

Tuesday 11 November 2008 1:13:45 pm

Alt 1:
You need pr user cache on those pages then, supported in 4.1, look here:
http://issues.ez.no/IssueView.php?Id=13274&activeItem=1
And clear cache with:
eZContentCache::cleanup( array( $nodeID ), $userID );

Alt 2:
Store node id's in cookie and show / hide the button based on that compared to current node id of the page.

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

Carlos Revillo

Tuesday 11 November 2008 2:49:41 pm

Thanks for the reply.

Site is online now. It's eZ 4.0.0. customer probably wants to migrate to 4.0.1. Is there any chance to apply your patch to a eZ 4.0.0 installation?

For second alternative i don't really follow you. we'll need to query this cookie for that, but, if viewcache is enabled, the response will be always the same, won't?

Carlos Revillo

Sunday 16 November 2008 10:17:21 am

Hi again Andre.

I have tried the patch and it works perfectly.
But it only works for a node. What we need is something similar for every object of a class.

Suppose you have an "article" class. it would be nice to add something to tell ez to generate cache files for every node of this class and not only for a node.

This way, when you add a new article and you want to add an "add to favourites" link you need to add an entry for

ViewCacheSettings[newNodeIDhere]=pr_user

I think it would be nice to add something like

ViewCacheSettingsByClass[30]=pr_user

or something like this. Do you think this is possible? I'll try myself and let you know if you want...

André R.

Sunday 16 November 2008 1:12:11 pm

Do you think this is possible?

It's possible but the node is not fetched yet at this point so it is not something I'll consider.
So you might want to rethink how you implement this, does the bookmark code really need to be in the node template instead of in the pagelayout?
Or you can implement it with some javascript in pagelayout to show / hide the add to bookmarks stuff, there you can use cache-blocks where you have higher flexibility on how you cache stuff.

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

Carlos Revillo

Sunday 16 November 2008 2:09:10 pm

At the point of the development it would be more difficult to pass the add to bookmars stuff than adding a cache_ttl to 0 for example.

I prefer not considering javascript option because accesibility (WAI) reasons.
Also, working with cache-blocks in this template, will me make to set a node_id as a expiry key... and i've told to use cache-blocks expiry keys as unique as possible. lot of cache-blocks could overhead the system.

My idea is to fetch node and get this class, so i was thinking about adding some code in kernel/content/view.php.

Getting your code from the svn at revision 25222, it would be something like

 $viewCacheSettings = $ini->variable( 'ContentSettings', 'ViewCacheSettings' );
    if ( isset( $viewCacheSettings[$NodeID] ) )
    {
        $viewCacheSetting = $viewCacheSettings[$NodeID];
        if ( $viewCacheSetting === 'disabled' )
        {
            $viewCacheEnabled = false;
        }
    }
	else
	{
		$viewCacheSettingsClass = $ini->variable( 'ContentSettings', 'ViewCacheSettingsClass' );
		$node = eZContentObjectTreeNode::fetch($NodeID);
		if ( isset( $viewCacheSettingsClass[$node->classIdentifier()] ) )
	    {
	        $viewCacheSetting = $viewCacheSettingsClass[$node->classIdentifier()];
	        if ( $viewCacheSetting === 'disabled' )
	        {
	            $viewCacheEnabled = false;
	        }
	    }
	}

and i would add another config variable in site.ini. My site.ini.append.php would probably looks like

[ContentSettings]
ViewCacheSettingsClass[article]=pr_user

Works in my tests, but i also think this is a "hack" to kernel/content/view.php that i would prefer not having to do :).