- add locking to custom resources (Forum Post 75252)

this is a potentially dirty commit
This commit is contained in:
rodneyrehm
2011-10-14 16:17:27 +00:00
parent ef3e29daa7
commit 8a82d84861
4 changed files with 52 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
===== trunk ===== ===== trunk =====
14.10.2011 14.10.2011
- bugfix unique_resource did not properly apply to compiled resources (Forum Topic 20128) - bugfix unique_resource did not properly apply to compiled resources (Forum Topic 20128)
- add locking to custom resources (Forum Post 75252)
13.10.2011 13.10.2011
- add caching for config files in Smarty_Resource - add caching for config files in Smarty_Resource

View File

@@ -150,6 +150,7 @@ abstract class Smarty_CacheResource {
} }
// try the instance cache // try the instance cache
if (isset(self::$resources[$type])) { if (isset(self::$resources[$type])) {
// FIXME: rodneyrehm need to validate if cache resource may be used in given $smarty.
return self::$resources[$type]; return self::$resources[$type];
} }
// try registered resource // try registered resource

View File

@@ -184,6 +184,55 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource {
$this->cache = array(); $this->cache = array();
return $this->delete($resource_name, $cache_id, $compile_id, $exp_time); return $this->delete($resource_name, $cache_id, $compile_id, $exp_time);
} }
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$id = $cached->filepath;
$name = $cached->source->name . '.lock';
$mtime = $this->fetchTimestamp($id, $name, null, null);
if ($mtime === null) {
$this->fetch($id, $name, null, null, &$content, &$mtime);
}
return $mtime && time() - $mtime < $smarty->locking_timeout;
}
/**
* Lock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = true;
$id = $cached->filepath;
$name = $cached->source->name . '.lock';
$this->save($id, $name, null, null, $smarty->locking_timeout, '');
}
/**
* Unlock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = false;
$id = $cached->filepath;
$name = $cached->source->name . '.lock';
$this->delete($name, null, null, null);
}
} }
?> ?>

View File

@@ -339,6 +339,7 @@ abstract class Smarty_Resource {
{ {
// try the instance cache // try the instance cache
if (isset(self::$resources[$resource_type])) { if (isset(self::$resources[$resource_type])) {
// FIXME: rodneyrehm need to validate if resource may be used in given $smarty.
return self::$resources[$resource_type]; return self::$resources[$resource_type];
} }