Esempio n. 1
0
 public function run()
 {
     $cacheKey = md5(__METHOD__);
     if (false === ($items = \Yii::$app->cache->get($cacheKey))) {
         $parents = ArrayHelper::map(PostMeta::find()->where(['parent' => null])->orWhere(['parent' => 0])->orderBy(['order' => SORT_ASC])->all(), 'id', 'name');
         foreach ($parents as $key => $value) {
             $nodes[$value] = PostMeta::find()->where(['parent' => $key])->asArray()->all();
         }
         $items = $nodes;
         //一天缓存
         \Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => [NamingHelper::getCommonTag(PostMeta::className())]]));
     }
     return $this->render('node', ['nodes' => $items]);
 }
Esempio n. 2
0
 /**
  * 查找活跃用户
  * @param int $limit
  * @return array|\yii\db\ActiveRecord[]
  */
 public static function findActiveUser($limit = 12)
 {
     $cacheKey = md5(__METHOD__ . $limit);
     if (false === ($items = \Yii::$app->cache->get($cacheKey))) {
         $items = User::find()->joinWith(['merit', 'userInfo'])->where([User::tableName() . '.status' => 10])->orderBy(['merit' => SORT_DESC, '(like_count+thanks_count)' => SORT_DESC])->limit($limit)->all();
         //一天缓存
         \Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => [NamingHelper::getCommonTag(User::className())]]));
     }
     return $items;
 }
 /**
  * Invalidate model tags.
  * @return bool
  */
 public function invalidateTags()
 {
     /** @var \DevGroup\TagDependencyHelper\TagDependencyTrait $this */
     \yii\caching\TagDependency::invalidate($this->getTagDependencyCacheComponent(), [static::commonTag(), Post::commonTag(), $this->objectTag(), NamingHelper::getObjectTag(Post::className(), $this->getPrimaryKey())]);
     return true;
 }