mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
- bugfix regression in Smarty_CacheReource_KeyValueStore introduced by r4261
- added APC test - added read/write test to APC demo ('cause it ain't working on my machine!?)
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== Smarty 3.1 trunk =====
|
===== Smarty 3.1 trunk =====
|
||||||
|
19.09.2011
|
||||||
|
- bugfix regression in Smarty_CacheReource_KeyValueStore introduced by r4261
|
||||||
|
|
||||||
18.09.2011
|
18.09.2011
|
||||||
- bugfix template caching did not care about file.tpl in different template_dir
|
- bugfix template caching did not care about file.tpl in different template_dir
|
||||||
- bugfix {include $file} was broken when merge_compiled_incluges = true
|
- bugfix {include $file} was broken when merge_compiled_incluges = true
|
||||||
|
@@ -14,10 +14,17 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore {
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// test if APC is present
|
// test if APC is present
|
||||||
if(!function_exists('apc_cache_info'))
|
if(!function_exists('apc_cache_info')) {
|
||||||
throw new Exception('APC Template Caching Error: APC is not installed');
|
throw new Exception('APC Template Caching Error: APC is not installed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apc_store(array('foo' => 'bar'));
|
||||||
|
$t = apc_fetch(array('foo'));
|
||||||
|
if (!$t || $t['foo'] != 'bar') {
|
||||||
|
throw new Exception('APC Template Caching Error: APC is not working properly');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read values for a set of keys from cache
|
* Read values for a set of keys from cache
|
||||||
*
|
*
|
||||||
|
@@ -69,7 +69,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||||
{
|
{
|
||||||
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp)) {
|
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, $cached->source->uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$cached->content = $content;
|
$cached->content = $content;
|
||||||
@@ -92,7 +92,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
$content = $cached->content ? $cached->content : null;
|
$content = $cached->content ? $cached->content : null;
|
||||||
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
||||||
if ($content === null || !$timestamp) {
|
if ($content === null || !$timestamp) {
|
||||||
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp)) {
|
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,23 +153,22 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
*/
|
*/
|
||||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||||
{
|
{
|
||||||
$cid = $this->buildCachedFilepath($smarty,$resource_name, $cache_id, $compile_id);
|
$uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id);
|
||||||
|
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
|
||||||
$this->delete(array($cid));
|
$this->delete(array($cid));
|
||||||
$this->invalidate($cid, $resource_name, $cache_id, $compile_id);
|
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get system filepath to cached file.
|
* Get template's unique ID
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param string $resource_name template name
|
* @param string $resource_name template name
|
||||||
* @param string $cache_id cache id
|
* @param string $cache_id cache id
|
||||||
* @param string $compile_id compile id
|
* @param string $compile_id compile id
|
||||||
* @return string filepath of cache file
|
* @return string filepath of cache file
|
||||||
* @uses sanitize() on $resource_name and $compile_id to avoid bad segments
|
|
||||||
*/
|
*/
|
||||||
protected function buildCachedFilepath(Smarty $smarty, $resource_name, $cache_id, $compile_id)
|
protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
|
||||||
{
|
{
|
||||||
$uid = '';
|
$uid = '';
|
||||||
if (isset($resource_name)) {
|
if (isset($resource_name)) {
|
||||||
@@ -180,7 +179,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
// remove from template cache
|
// remove from template cache
|
||||||
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
}
|
}
|
||||||
return $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
|
return $uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,16 +207,17 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
* @param string $compile_id compile id
|
* @param string $compile_id compile id
|
||||||
* @param string $content cached content
|
* @param string $content cached content
|
||||||
* @param integer &$timestamp cached timestamp (epoch)
|
* @param integer &$timestamp cached timestamp (epoch)
|
||||||
|
* @param string $resource_uid resource's uid
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null)
|
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null)
|
||||||
{
|
{
|
||||||
$t = $this->read(array($cid));
|
$t = $this->read(array($cid));
|
||||||
$content = !empty($t[$cid]) ? $t[$cid] : null;
|
$content = !empty($t[$cid]) ? $t[$cid] : null;
|
||||||
$timestamp = null;
|
$timestamp = null;
|
||||||
|
|
||||||
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
|
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
|
||||||
$invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id);
|
$invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
|
||||||
if ($invalidated > $timestamp) {
|
if ($invalidated > $timestamp) {
|
||||||
$timestamp = null;
|
$timestamp = null;
|
||||||
$content = null;
|
$content = null;
|
||||||
@@ -262,9 +262,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
* @param string $resource_name template name
|
* @param string $resource_name template name
|
||||||
* @param string $cache_id cache id
|
* @param string $cache_id cache id
|
||||||
* @param string $compile_id compile id
|
* @param string $compile_id compile id
|
||||||
|
* @param string $resource_uid source's uid
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null)
|
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
|
||||||
{
|
{
|
||||||
$now = microtime(true);
|
$now = microtime(true);
|
||||||
$key = null;
|
$key = null;
|
||||||
@@ -274,7 +275,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
}
|
}
|
||||||
// invalidate all caches by template
|
// invalidate all caches by template
|
||||||
else if ($resource_name && !$cache_id && !$compile_id) {
|
else if ($resource_name && !$cache_id && !$compile_id) {
|
||||||
$key = 'IVK#TEMPLATE#' . $this->sanitize($resource_name);
|
$key = 'IVK#TEMPLATE#' . $resource_uid . '#' . $this->sanitize($resource_name);
|
||||||
}
|
}
|
||||||
// invalidate all caches by cache group
|
// invalidate all caches by cache group
|
||||||
else if (!$resource_name && $cache_id && !$compile_id) {
|
else if (!$resource_name && $cache_id && !$compile_id) {
|
||||||
@@ -298,18 +299,20 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
* @param string $resource_name template name
|
* @param string $resource_name template name
|
||||||
* @param string $cache_id cache id
|
* @param string $cache_id cache id
|
||||||
* @param string $compile_id compile id
|
* @param string $compile_id compile id
|
||||||
|
* @param string $resource_uid source's filepath
|
||||||
* @return float the microtime the CacheID was invalidated
|
* @return float the microtime the CacheID was invalidated
|
||||||
*/
|
*/
|
||||||
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null)
|
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
|
||||||
{
|
{
|
||||||
// abort if there is no CacheID
|
// abort if there is no CacheID
|
||||||
if (false && !$cid) {
|
if (false && !$cid) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// abort if there are no InvalidationKeys to check
|
// abort if there are no InvalidationKeys to check
|
||||||
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id))) {
|
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// there are no InValidationKeys
|
// there are no InValidationKeys
|
||||||
if (!($values = $this->read($_cid))) {
|
if (!($values = $this->read($_cid))) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -328,15 +331,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
* @param string $resource_name template name
|
* @param string $resource_name template name
|
||||||
* @param string $cache_id cache id
|
* @param string $cache_id cache id
|
||||||
* @param string $compile_id compile id
|
* @param string $compile_id compile id
|
||||||
|
* @param string $resource_uid source's filepath
|
||||||
* @return array list of InvalidationKeys
|
* @return array list of InvalidationKeys
|
||||||
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
|
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
|
||||||
*/
|
*/
|
||||||
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null)
|
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
|
||||||
{
|
{
|
||||||
$t = array('IVK#ALL');
|
$t = array('IVK#ALL');
|
||||||
$_name = $_compile = '#';
|
$_name = $_compile = '#';
|
||||||
if ($resource_name) {
|
if ($resource_name) {
|
||||||
$_name .= $this->sanitize($resource_name);
|
$_name .= $resource_uid . '#' . $this->sanitize($resource_name);
|
||||||
$t[] = 'IVK#TEMPLATE' . $_name;
|
$t[] = 'IVK#TEMPLATE' . $_name;
|
||||||
}
|
}
|
||||||
if ($compile_id) {
|
if ($compile_id) {
|
||||||
|
Reference in New Issue
Block a user