Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3.1.30 and MemCached

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
tourispo
Smarty n00b


Joined: 16 Oct 2015
Posts: 3

PostPosted: Tue Mar 21, 2017 2:59 pm    Post subject: Smarty 3.1.30 and MemCached Reply with quote

Hey Smarty Team,
we are currently using Smarty 3.1.30 and make heavy use of Caching. We have thousands of files organised in CacheGroups like:
Quote:
www.tourispo.com|desktop|site|sections|desktop|loggedout|css|


We were moving all our caching into MemCached which worked great with all ZendFramework Caching, however I badly failed using MemCached with Smarty cache. First of all in that file: https://github.com/smarty-php/smarty/blob/master/demo/plugins/cacheresource.memcache.php ...
there is a line of code:
Code:
 $res = $this->memcache->get($_keys);


However this only works in Memcache not in Memcached (see the d at the end). It fails with
Quote:
Memcached::get() expects parameter 1 to be string, array given
as Memcached::get() expects a string as a key and not an array. Please note that Memcache::get() (Memcache WITHOUT the d) can use both string and key. I could fix this by replacing the line with...

Code:
 $res = $this->memcache->getMulti($_keys);


However if done, I get the following error message on the first page load (empty cache):
Quote:
Fatal error: Uncaught --> Smarty: Invalid compiled template for '/var/www/sgtest/htdocs/templates/desktop/sections/frame/headerStart.tpl


My question would be if anyone has ever succeeded using Memcached (not Memcache) with Smarty. If yes is there a plugin that also handles clearing groups of CacheGroups (i.e. clear all templates in www.tourispo.com|desktop|site|sections|...). I think that is all missing for the current CacheHandler linked in the file above.

Thanks for all comments and help
Martin
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Mar 21, 2017 3:10 pm    Post subject: Reply with quote

You'll have to write your own cache implementation, I'm afraid.
See http://www.smarty.net/docs/en/caching.custom.tpl for details.

Alternatively, search internet for ready solutions.
One I googled is https://github.com/edofrederix/Smarty-Memcached
Back to top
View user's profile Send private message
tourispo
Smarty n00b


Joined: 16 Oct 2015
Posts: 3

PostPosted: Tue Mar 21, 2017 4:00 pm    Post subject: Reply with quote

Hello AnrDaemon,
thanks for your quick reply. The solution you just posted is not a plugin but a class which extends Smarty. This is not what I meant as it does not only override caching but also whole methods like fetch():
Quote:
...instead of calling the Smarty fetch() class function, you
now call $smarty->Memcached_fetch($key, $tpl, $ttl)...


I think I could really implement this plugin with maybe some guidance. What I don't get is why I get the:

Code:

Fatal error: Uncaught --> Smarty: Invalid compiled template for '/var/www/sgtest/htdocs/templates/desktop/sections/frame/headerStart.tpl


On first page load.. There shouldn't be any cached file anyways due to an empty cache....[/code]
Back to top
View user's profile Send private message
tourispo
Smarty n00b


Joined: 16 Oct 2015
Posts: 3

PostPosted: Tue Mar 21, 2017 5:05 pm    Post subject: Reply with quote

UPDATE: The same happens when I use Memcache (without the d) for which there is already a suggested custom Cache implementation at: http://www.smarty.net/docs/en/caching.custom.tpl called Smarty_CacheResource_Memcache

As soon as I switch to this implementation I get:
Quote:

Fatal error: Uncaught --> Smarty: Invalid compiled template for '/var/www/sgtest/htdocs/templates/desktop/sections/frame/headerStart.tpl


Switching to file based caching works perfectly. Isn't this CacheResource on official Smarty page supposed to work??
Thanks
Martin
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP