CDbCacheDependency

优质
小牛编辑
124浏览
2023-12-01
所有包 | 属性 | 方法
system.caching.dependencies
继承class CDbCacheDependency » CCacheDependency » CComponent
实现ICacheDependency
源自1.0
版本$Id: CDbCacheDependency.php 3204 2011-05-05 21:36:32Z alexander.makarow $
源码framework/caching/dependencies/CDbCacheDependency.php
CDbCacheDependency指基于SQL语句查询结果的依赖项。

若查询结果(一个量)改变了,则认为该依赖项改变。 设置sql属性以指定SQL语句。 connectionID属性指定了CDbConnection应用组件的ID。 它是用来执行查询的数据库连接。

公共属性

隐藏继承属性

属性类型描述定义在
connectionIDstringCDbConnection应用组件的ID。默认是‘db’。CDbCacheDependency
dependentDatamixed用以决定依赖项是否被改变的数据。 这些数据是可用的在evaluateDependency被调用后。CCacheDependency
hasChangedboolean依赖项是否被改变。CCacheDependency
paramsarray绑定到sql指定的SQL语句的参数(名=>值)。CDbCacheDependency
sqlstringSQL语句,它的查询结果用来决定依赖项是否被改变。 注意,该SQL语句应该返回一个单一的值。CDbCacheDependency

受保护属性

隐藏继承属性

属性类型描述定义在
dbConnectionCDbConnection数据库连接实例。CDbCacheDependency

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造器。CDbCacheDependency
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__sleep()PHP的魔术方法sleep。CDbCacheDependency
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateDependency()根据依赖关系来生存和保存数据以计算依赖项。CCacheDependency
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getDependentData()返回用以决定依赖项是否被改变的数据。 这些数据是可用的在evaluateDependency被调用后。CCacheDependency
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getHasChanged()返回依赖项是否被改变。CCacheDependency
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
raiseEvent()发起一个事件。CComponent

受保护方法

隐藏继承方法

方法描述定义在
generateDependentData()生成决定依赖项是否被改变需要的数据。CDbCacheDependency
getDbConnection()返回数据库连接实例。CDbCacheDependency

属性详细

connectionID 属性 public string $connectionID;

CDbConnection应用组件的ID。默认是‘db’。

dbConnection 属性 只读 protected CDbConnection getDbConnection()

数据库连接实例。

params 属性 (可用自 v1.1.4) public array $params;

绑定到sql指定的SQL语句的参数(名=>值)。

sql 属性 public string $sql;

SQL语句,它的查询结果用来决定依赖项是否被改变。 注意,该SQL语句应该返回一个单一的值。

方法详细

__construct() 方法
public void __construct(string $sql=NULL)
$sqlstringSQL语句,它的查询结果用来决定依赖项是否被改变。
源码: framework/caching/dependencies/CDbCacheDependency.php#47 (显示) publicfunction__construct($sql=null)
{
$this->sql=$sql;
}

构造器。

__sleep() 方法
public array __sleep()
{return}array
源码: framework/caching/dependencies/CDbCacheDependency.php#57 (显示) publicfunction__sleep()
{
$this->_db=null;
returnarray_keys((array)$this);
}

PHP的魔术方法sleep。 该方法保证数据库实例是null,因为它包含了资源句柄。

generateDependentData() 方法
protected mixed generateDependentData()
{return}mixed决定依赖项是否被改变需要的数据。
源码: framework/caching/dependencies/CDbCacheDependency.php#68 (显示) protectedfunctiongenerateDependentData()
{
if($this->sql!==null)
{
$db=$this->getDbConnection();
$command=$db->createCommand($this->sql);
if(is_array($this->params))
{
foreach($this->paramsas$name=>$value)
$command->bindValue($name,$value);
}
if($db->queryCachingDuration>0)
{
//temporarilydisableandre-enablequerycaching
$duration=$db->queryCachingDuration;
$db->queryCachingDuration=0;
$result=$command->queryRow();
$db->queryCachingDuration=$duration;
}
else
$result=$command->queryRow();
return$result;
}
else
thrownewCException(Yii::t('yii','CDbCacheDependency.sqlcannotbeempty.'));
}

生成决定依赖项是否被改变需要的数据。 该方法返回全局状态的值。

getDbConnection() 方法
protected CDbConnection getDbConnection()
{return}CDbConnection数据库连接实例。
源码: framework/caching/dependencies/CDbCacheDependency.php#99 (显示) protectedfunctiongetDbConnection()
{
if($this->_db!==null)
return$this->_db;
else
{
if(($this->_db=Yii::app()->getComponent($this->connectionID))instanceofCDbConnection)
return$this->_db;
else
thrownewCException(Yii::t('yii','CDbCacheDependency.connectionID"{id}"isinvalid.PleasemakesureitreferstotheIDofaCDbConnectionapplicationcomponent.',
array('{id}'=>$this->connectionID)));
}
}