public function testGetObjectTag()
 {
     $ar = new Table();
     $this->assertEquals($ar->className() . '[ObjectTag:1]', ActiveRecordCacheTags::getObjectTag($ar, 1));
     $this->assertEquals($ar->className() . '[ObjectTag:1|2]', ActiveRecordCacheTags::getObjectTag($ar, ['id1' => 1, 'id2' => 2]));
     $this->assertEquals($ar->className() . '[ObjectTag:1|2]', ActiveRecordCacheTags::getObjectTag($ar, ['id2' => 2, 'id1' => 1]));
 }
コード例 #2
0
 /**
  * Analogue cachedFindOne, but use only for search by primary key
  * @param mixed $condition
  * @param int $cacheTtl
  * @return null|\yii\db\ActiveRecord
  */
 public static function cachedFindOneByPk($condition, $cacheTtl = 86400)
 {
     return self::cachedFind($condition, static::class . ':pk:' . ActiveRecordCacheTags::serializeCondition($condition), ActiveRecordCacheTags::getObjectTag(static::class, $condition), function ($condition) {
         return static::findByCondition($condition)->one();
     }, $cacheTtl);
 }
コード例 #3
0
 /**
  * Invalidate model tags.
  * @return bool
  */
 public function invalidateTags()
 {
     TagDependency::invalidate($this->getCacheComponent(), [ActiveRecordCacheTags::getCommonTag($this->owner), ActiveRecordCacheTags::getObjectTag($this->owner, $this->owner->getPrimaryKey())]);
     return true;
 }