Пример #1
0
 public function cache($key, Closure $closure)
 {
     $key = 'standard:' . get_class($this) . ':model:' . $key;
     if (!RedisFacade::exist($key)) {
         RedisFacade::set($key, json_encode($closure()));
     }
     return json_decode(RedisFacade::get($key));
 }
Пример #2
0
 public function getStaticsByMonth($repo = null)
 {
     $className = static::class;
     $repoName = $repo == null ? 'Files' : $repo;
     $key = 'standard:archives:' . $repoName;
     if (!RedisFacade::exist($key)) {
         $query = $className::query()->columns(['count(' . $className . '.id) AS num', 'DATE_FORMAT(' . $className . '.created_at,"%Y-%m") As month'])->groupBy('month')->orderBy('month DESC');
         if ($repo) {
             $query = $query->rightJoin($repo, 'sub.file_id = ' . $className . '.id', 'sub');
         }
         $results = $query->execute();
         RedisFacade::set($key, json_encode($results));
     }
     return json_decode(RedisFacade::get($key));
 }
Пример #3
0
 public function getMyTags()
 {
     if (!RedisFacade::isTagsExist()) {
         RedisFacade::setTags($this->getMyTagsFromDatabase());
     }
     return RedisFacade::getTags();
 }
Пример #4
0
<?php

$em = new myEventManager();
$em->attach('auth', new authEventsHandler());
$em->listen('tags:updateTag', cacheEventsHandler::class . '::deleteTagsCache');
$em->listen('tags:updateTag', tagsEventsHandler::class . '::updateMeta');
$em->attach('taggables', new taggablesEventsHandler());
$em->attach('standards:addWebFile', function ($event, \Phalcon\Mvc\Model $model) {
    RedisFacade::delete('standard:archives:' . get_class($model));
    RedisFacade::delete('standard:archives:Files');
});
$em->attach('standards:addFile', function ($event, $model) {
    RedisFacade::delete('standard:archives:Files');
});
$em->attach('standards:deleteFile', function ($event, Files $file) {
    $model = $file->getFileable();
    if ($model) {
        RedisFacade::delete('standard:archives:' . get_class($model));
    }
    RedisFacade::delete('standard:archives:Files');
});
$em->attach('standards:deleteSelectedFiles', function ($event, $files) {
    RedisFacade::delete(RedisFacade::keys('standard:archives:*'));
});
return $em;