Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Memcache Custom Cache Implementation

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
sarabtech
Smarty Rookie


Joined: 06 Aug 2014
Posts: 5

PostPosted: Fri Mar 17, 2017 2:46 pm    Post subject: Memcache Custom Cache Implementation Reply with quote

Hi All,

I'm using the following code for memcache for smarty caching.

PHP: 5.6.26
Smarty: 3.1.31 (via composer)
Memcache: 1.4.4
Plugin: https://github.com/smarty-php/smarty/blob/master/demo/plugins/cacheresource.memcache.php


Code:

$rootDir = (dirname(__DIR__));
define("ROOTPATH", $rootDir);

$vendorPath = ROOTPATH . "/vendor";
$frontEndDir = ROOTPATH . "/frontend";

require_once $vendorPath . '/autoload.php';

$smarty = new Smarty();
$smarty->caching_type = 'memcache';

$smarty->compile_dir = $frontEndDir . '/test/templates_c';
$smarty->cache_dir = $frontEndDir . '/test/templates_c/cache';
$smarty->template_dir = $frontEndDir . '/test/templates/';
$smarty->plugins_dir = ROOTPATH . "/smarty_plugins";


//$smarty->clearAllCache();

$smarty->caching = 2;
$smarty->cache_lifetime = (mktime(0, 0, 0, date('n'), date('j') + 1) - time());

$isCached = $smarty->isCached('test.tpl', 'test');

if (!$isCached) {
    $smarty->assign('test', "Memcache Test");
} else {
    echo "No cache";
}

$smarty->display("test.tpl", 'test');


test.tpl

Code:

<b>{$test|lower}</b>


Error:
SmartyCompilerException: Syntax error in template "file:/home/www/test/templates/test.tpl" on line 1 "<b>{$test|lower}</b>" unknown modifier "lower" in /home/www/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 1

Kindly help me to resole this issue.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1055

PostPosted: Fri Mar 17, 2017 3:08 pm    Post subject: Re: Memcache Custom Cache Implementation Reply with quote

sarabtech wrote:
Hi All,

I'm using the following code for memcache

Irrelevant.

Quote:

test.tpl

Code:

<b>{$test|lower}</b>


Error:
SmartyCompilerException: Syntax error in template "file:/home/www/test/templates/test.tpl" on line 1 "<b>{$test|lower}</b>" unknown modifier "lower" in /home/www/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 1

Kindly help me to resole this issue.

Double check loading of standard Smarty classes.
Back to top
View user's profile Send private message
sarabtech
Smarty Rookie


Joined: 06 Aug 2014
Posts: 5

PostPosted: Mon Mar 20, 2017 5:06 am    Post subject: Reply with quote

Hi Admin,

Smarty is working perfectly. If I use any modifiers like "upper" or "truncate" or "lower", then I'm getting that error message.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1055

PostPosted: Mon Mar 20, 2017 3:09 pm    Post subject: Reply with quote

mods-2017-03-20.php5
Code:
<?php

require 'init.php';

$smarty->display(__FILE__);

__halt_compiler();
?>PHP {$smarty.const.PHP_VERSION}
Smarty {$smarty.version}

"Test"|upper: {"Test"|upper}
"Test"|lower: {"Test"|lower}
"Test truncated"|truncate:7: {"Test truncated"|truncate:7:"…"}


Code:
PHP 5.6.30
Smarty 3.1.31

"Test"|upper: TEST
"Test"|lower: test
"Test truncated"|truncate:7: Test…


PHP 7.0 same results. Check your autoloading settings.
Back to top
View user's profile Send private message
sarabtech
Smarty Rookie


Joined: 06 Aug 2014
Posts: 5

PostPosted: Tue Mar 21, 2017 11:01 am    Post subject: Reply with quote

Hi Admin,

Kindly note the following in my code:

$smarty->plugins_dir = ROOTPATH . "/smarty_plugins";

$smarty->caching_type = 'memcache';
(OR)
$smarty->caching_type = 'mysql';

In Plugin dir, I have the following plugins, I have the following files given in this URL http://www.smarty.net/docs/en/caching.custom.tpl

Quote:

I put Custom CacheResources in a file cacheresource.memcache.php within $plugins_dir and set $caching_type to invoke custom CacheResource implementation.



If I remove,

$smarty->caching_type = 'memcache';
(OR)
$smarty->caching_type = 'mysql';

I'm getting the expected result.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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