Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nocache in cachable plugins #929

Open
kkFelix opened this issue Jan 25, 2024 · 0 comments
Open

nocache in cachable plugins #929

kkFelix opened this issue Jan 25, 2024 · 0 comments

Comments

@kkFelix
Copy link

kkFelix commented Jan 25, 2024

Is there any way to use nocache tags or other methods to display uncached content within a cachable plugin?
This is my test code:

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
$smarty = new Smarty();
$smarty->setCacheDir(__DIR__ . '/cache');
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCompileDir(__DIR__ . '/compile');
$smarty->assign('dyn', microtime(true), true);
$smarty->assign('stat1', microtime(true));
$smarty->assign('stat2', microtime(true));
$smarty->registerPlugin(
    Smarty::PLUGIN_FUNCTION,
    'testFunc',
    static function ($params, $smarty) {
        return $smarty->fetch('string:test@plugin: {$dyn}, {$stat1}, {nocache}{$stat2}{/nocache}');
    },
    true
);
$smarty->display('string:test@index: {$dyn}, {$stat1}, {nocache}{$stat2}{/nocache}<br>{testFunc}');

The output from the display() call behaves correctly: the $dyn variable stays dynamic since it was assigned with cachable=false, $stat1 stays static and $stat2 within the nocache-tags also is dynamic.

Within the plugin however, all 3 variables are always cached.

test@index: 1706176477.52, 1706176474.2449, 1706176477.52
test@plugin: 1706176474.2449, 1706176474.2449, 1706176474.2449
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant