mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- add locking to custom resources (Forum Post 75252)
this is a potentially dirty commit
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== trunk =====
|
||||
14.10.2011
|
||||
- bugfix unique_resource did not properly apply to compiled resources (Forum Topic 20128)
|
||||
- add locking to custom resources (Forum Post 75252)
|
||||
|
||||
13.10.2011
|
||||
- add caching for config files in Smarty_Resource
|
||||
|
@@ -150,6 +150,7 @@ abstract class Smarty_CacheResource {
|
||||
}
|
||||
// try the instance cache
|
||||
if (isset(self::$resources[$type])) {
|
||||
// FIXME: rodneyrehm need to validate if cache resource may be used in given $smarty.
|
||||
return self::$resources[$type];
|
||||
}
|
||||
// try registered resource
|
||||
|
@@ -184,6 +184,55 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource {
|
||||
$this->cache = array();
|
||||
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);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -339,6 +339,7 @@ abstract class Smarty_Resource {
|
||||
{
|
||||
// try the instance cache
|
||||
if (isset(self::$resources[$resource_type])) {
|
||||
// FIXME: rodneyrehm need to validate if resource may be used in given $smarty.
|
||||
return self::$resources[$resource_type];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user