确定 smarty 何时创建缓存文件

发布于 2024-12-09 15:16:10 字数 162 浏览 0 评论 0 原文

我有一个cms,每个页面都在数据库中存储最后更新的时间。我已经在 smarty (3.1)中设置了缓存,但我希望能够清除缓存并强制它创建一个新的缓存文件(如果页面自上次保存的缓存文件以来已更新),但要做到这一点我需要了解缓存文件何时创建。

有没有办法获取缓存文件的时间戳?

谢谢

I've got a cms, each page stores the time that it was last updated in a database. I've got caching set up in smarty (3.1), but I want to be able to clear the cache and force it to create a new cache file if the page was updated since the last saved cache file, but to do that I need to know when the cached file was created.

Is there a way of getting the timestamp of the cached file?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2024-12-16 15:16:11

我最近回答了一个类似的问题:Smarty在数据库中缓存站点属性

<?php
// fill these if you do cache grouping and or have different compiles of the same template
$template = 'foobar.tpl';
$cache_id = null;
$compile_id = null;

$smarty = new Smarty();
$tpl = $smarty->createTemplate($template, $cache_id, $compile_id);
if ($tpl->isCached() && $tpl->cached->timestamp < $yourTimestampFromDB) {
  $smarty->clearCache($template, $cache_id, $compile_id);
}

I have recently answered a similar question: Smarty cache site properties in database

<?php
// fill these if you do cache grouping and or have different compiles of the same template
$template = 'foobar.tpl';
$cache_id = null;
$compile_id = null;

$smarty = new Smarty();
$tpl = $smarty->createTemplate($template, $cache_id, $compile_id);
if ($tpl->isCached() && $tpl->cached->timestamp < $yourTimestampFromDB) {
  $smarty->clearCache($template, $cache_id, $compile_id);
}
薔薇婲 2024-12-16 15:16:11

我不确定 Smarty 是否有任何内部功能。但是看看 filemtime()filectime 分别用于确定文件上次修改和更改的时间。

来自 php.net:

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last changed: " . date("F d Y H:i:s.", filectime($filename));
}

修改时间和更改时间之间的区别:

注意:在大多数 Unix 文件系统中,当文件的 inode 数据发生更改时,该文件就被视为已更改;也就是说,当更新 inode 中的权限、所有者、组或其他元数据时。另请参见 filemtime()(当您想要在网页上创建“上次修改”页脚时要使用它)和 fileatime()。

I'm not sure Smarty has anything internal for this. But look at filemtime() and filectime for determining when a file was last modified and changed respectively.

From php.net:

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last changed: " . date("F d Y H:i:s.", filectime($filename));
}

Difference between modified-time and change-time:

Note: In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated. See also filemtime() (which is what you want to use when you want to create "Last Modified" footers on web pages) and fileatime().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文