mirror of
https://github.com/smarty-php/smarty.git
synced 2025-07-29 15:37:14 +02:00
Fixing forced OpCache invalidation on every template include, which is resulting in fast raising wasted OpCache memory #1007 (#1047)
* Fixing forced OpCache Invalidation on every call, which is resulting in fast raising wasted memory * Fix undefined $path variable warning --------- Co-authored-by: Daniel Metzner <daniel.metzner@niceshops.com>
This commit is contained in:
@ -56,11 +56,14 @@ class FilePlugin extends BasePlugin {
|
||||
* @param Source $source source object
|
||||
*/
|
||||
public function populateTimestamp(Source $source) {
|
||||
if (!$source->exists && $path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig)) {
|
||||
$source->timestamp = $source->exists = is_file($path);
|
||||
$path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig);
|
||||
if (!$source->exists) {
|
||||
$source->exists = ($path !== false && is_file($path));
|
||||
}
|
||||
if ($source->exists && $path) {
|
||||
if ($source->exists && $path !== false) {
|
||||
$source->timestamp = filemtime($path);
|
||||
} else {
|
||||
$source->timestamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ class Compiled extends GeneratedPhpFile {
|
||||
if ($this->exists && !$_smarty_tpl->getSmarty()->force_compile
|
||||
&& !($_smarty_tpl->compile_check && $_smarty_tpl->getSource()->getTimeStamp() > $this->getTimeStamp())
|
||||
) {
|
||||
$this->loadCompiledTemplate($_smarty_tpl);
|
||||
$this->loadCompiledTemplate($_smarty_tpl, false);
|
||||
}
|
||||
|
||||
if (!$this->isValid) {
|
||||
@ -241,16 +241,19 @@ class Compiled extends GeneratedPhpFile {
|
||||
* HHVM requires a workaround because of a PHP incompatibility
|
||||
*
|
||||
* @param Template $_smarty_tpl do not change/remove variable name, is used by compiled template
|
||||
* @param bool $invalidateCachedFiles forces a revalidation of the file in opcache or apc cache (if available)
|
||||
*
|
||||
*/
|
||||
private function loadCompiledTemplate(Template $_smarty_tpl) {
|
||||
|
||||
if (function_exists('opcache_invalidate')
|
||||
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
||||
) {
|
||||
opcache_invalidate($this->filepath, true);
|
||||
} elseif (function_exists('apc_compile_file')) {
|
||||
apc_compile_file($this->filepath);
|
||||
private function loadCompiledTemplate(Template $_smarty_tpl, bool $invalidateCachedFiles = true) {
|
||||
|
||||
if ($invalidateCachedFiles) {
|
||||
if (function_exists('opcache_invalidate')
|
||||
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
||||
) {
|
||||
opcache_invalidate($this->filepath, true);
|
||||
} elseif (function_exists('apc_compile_file')) {
|
||||
apc_compile_file($this->filepath);
|
||||
}
|
||||
}
|
||||
if (defined('HHVM_VERSION')) {
|
||||
eval('?>' . file_get_contents($this->filepath));
|
||||
|
Reference in New Issue
Block a user