smarty-php / smarty-php/smarty

Smarty delete cache issues

Open
#1,110 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

Hi,

We recently updated Smarty to v5.4.3 (the latest git recommendation).

We first ran into issues because Smarty added 'setCacheResource' but didn't give depreciation warnings on the old setting, so we fell back to file caching instead of the caching in Redis as we do.

Today, we discovered an even more concerning issue. We ran into issues with clearing the cache.

In FIlePlugin.php:

when creating template _joined_template_dir is like public/emag/article.tpl/var/www/templates/tpl/

when getting cached (on deletion) is like public/emag/article.tpl

Our setup:

$smarty->setTemplateDir(_TEMPLATES_DIR . '/tpl/');
$smarty->setCompileDir(_TEMPLATES_DIR . '/compile/');
$smarty->setConfigDir(_TEMPLATES_DIR . '/config/');
$smarty->setCacheDir('/tmp/templates/');
$smarty->setCaching(1);
$smarty->setCompileCheck(true);
$smarty->setCacheDir('/tmp/templates/');
$smarty->setCacheResource(new Smarty_CacheResource_Redis);
Are we missing something?

We eventually solved it for now by changing these lines below, but it would be good to include a fix in the official version.

KeyValueStore.php

$cid = $uid . '#' . $this->getTemplate($smarty, $resource_name)->type . '_' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);

protected function getTemplate(Smarty $smarty, $resource_name)
{
if (isset($resource_name)) {
$source = \Smarty\Template\Source::load(null, $smarty, $resource_name);
return $source;
}
return '';
}
FilePlugin.php

$source->getSmarty()->getTemplateDir(0))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read KeyValueStore.php and FilePlugin.php first, focusing on how the template resource name is converted into cache keys during creation and deletion. Compare the differing resource paths shown in the report and verify that Redis cache clearing uses the same template identity as cache creation. Done means the reported cache entries can be cleared reliably with Smarty 5.4.3.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, redis
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.