- improvement invalidate OPCACHE for cleared compiled and cached template files (forum topic 25557)

This commit is contained in:
uwetews
2015-09-15 00:15:12 +02:00
parent 6ff3505a37
commit 0eb7f4b8d1
5 changed files with 25 additions and 9 deletions
@@ -82,13 +82,16 @@ class Smarty_Internal_Extension_Clear
}
}
// check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) {
if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) ||
$_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)
) {
continue;
}
// check cache id
if (isset($_cache_id)) {
// count of cache id parts
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset :
$_parts_count - 1 - $_compile_id_offset;
if ($_parts_count < $_cache_id_parts_count) {
continue;
}
@@ -114,12 +117,15 @@ class Smarty_Internal_Extension_Clear
// remove from template cache
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached) && $tpl->cached->filepath == (string)$_file) {
if (isset($tpl->cached) && $tpl->cached->filepath == (string) $_file) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
$_count += @unlink((string) $_file) ? 1 : 0;
if (function_exists('opcache_invalidate')) {
opcache_invalidate((string) $_file);
}
}
}
}
@@ -91,10 +91,11 @@ class Smarty_Internal_Method_ClearCompiledTemplate
if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) &&
$a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) &&
(!isset($resource_name) || (isset($_filepath[$_resource_part_1_length]) &&
substr_compare($_filepath, $_resource_part_1, - $_resource_part_1_length, $_resource_part_1_length) ==
0) || (isset($_filepath[$_resource_part_2_length]) &&
substr_compare($_filepath, $_resource_part_2, - $_resource_part_2_length, $_resource_part_2_length) ==
0))
substr_compare($_filepath, $_resource_part_1, - $_resource_part_1_length,
$_resource_part_1_length) == 0) ||
(isset($_filepath[$_resource_part_2_length]) &&
substr_compare($_filepath, $_resource_part_2, - $_resource_part_2_length,
$_resource_part_2_length) == 0))
) {
if (isset($exp_time)) {
if (time() - @filemtime($_filepath) >= $exp_time) {
@@ -114,6 +115,9 @@ class Smarty_Internal_Method_ClearCompiledTemplate
}
}
$_count ++;
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_filepath);
}
}
}
}