自 1.22.x 以来清除 Twig 中整个缓存的惯用方法是什么?
What is idiomatic way to clear whole cache in Twig since 1.22.x?
自 1.22.0
版本 Twig
起,方法 Twig_Environment::clearCacheFiles()
已弃用。但是,我没有在任何地方(无论是在文档中,还是在回购票中,也不是在 SO 上)找到可以替代这种已弃用方法的东西。
那么现在清除所有缓存文件的惯用(且未弃用)方法是什么?
通过实现自己的函数来清除这些文件似乎很奇怪。
所以没有新的惯用方法来清除所有缓存文件。
Twig
项目维护者自行将其留给图书馆用户。参数是:
The argument was that Twig itself will only support filesystem cache (due to opcache). Thus clear() would be the same as removing the cache folder manually. Thus it doesn't need to be in the interface. So you have to clear your cache either manually or write the method yourself.
可以在@alain-tiemblo 早期在评论中提到的 relevant issue 中阅读更多详细信息。
如果您有兴趣,可以将 Twig 中已弃用的方法制作成通用函数。它只删除叶节点(Twig 生成的 php 文件)但保留目录。您需要确保传递的路径正确。
function clearCacheFiles($cacheLocation) {
if (is_string($cacheLocation)) {
foreach (new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($cacheLocation),
\RecursiveIteratorIterator::LEAVES_ONLY) as $file
) {
if ($file->isFile()) {
@unlink($file->getPathname());
}
}
}
}
来自 Twig/lib/Twig/Environment.php 首次标记为已弃用时的样子。
自 1.22.0
版本 Twig
起,方法 Twig_Environment::clearCacheFiles()
已弃用。但是,我没有在任何地方(无论是在文档中,还是在回购票中,也不是在 SO 上)找到可以替代这种已弃用方法的东西。
那么现在清除所有缓存文件的惯用(且未弃用)方法是什么?
通过实现自己的函数来清除这些文件似乎很奇怪。
所以没有新的惯用方法来清除所有缓存文件。
Twig
项目维护者自行将其留给图书馆用户。参数是:
The argument was that Twig itself will only support filesystem cache (due to opcache). Thus clear() would be the same as removing the cache folder manually. Thus it doesn't need to be in the interface. So you have to clear your cache either manually or write the method yourself.
可以在@alain-tiemblo 早期在评论中提到的 relevant issue 中阅读更多详细信息。
如果您有兴趣,可以将 Twig 中已弃用的方法制作成通用函数。它只删除叶节点(Twig 生成的 php 文件)但保留目录。您需要确保传递的路径正确。
function clearCacheFiles($cacheLocation) {
if (is_string($cacheLocation)) {
foreach (new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($cacheLocation),
\RecursiveIteratorIterator::LEAVES_ONLY) as $file
) {
if ($file->isFile()) {
@unlink($file->getPathname());
}
}
}
}
来自 Twig/lib/Twig/Environment.php 首次标记为已弃用时的样子。