Пример #1
0
 /**
  * @param CoreInterface $core
  */
 public function __construct(CoreInterface $core)
 {
     $this->core = $core;
     $cache = IlluminateCache::store($this->getCacheStore());
     if ($tags = $this->getCacheTags()) {
         $cache = $cache->tags($tags);
     }
     $this->cache = $cache;
 }
Пример #2
0
 public function __construct(Database $database, $cacheName = null, $lifetime = null)
 {
     $this->database = $database;
     if ($cacheName) {
         $this->cache = Cache::store($cacheName);
         $this->lifetime = $lifetime;
     } else {
         $this->cache = null;
         $this->lifetime = 0;
     }
 }
Пример #3
0
 public function getArticle($id)
 {
     return Cache::store($this->store)->rememberForever($id, function () use($id) {
         $article_model = new Articles();
         $article = $article_model->published()->getById($id)->with('tags', 'category')->first();
         $data = ['id' => $article->id, 'title' => $article->title, 'curl' => $article->curl, 'keywords' => $article->meta_keywords, 'description' => $article->meta_description, 'content' => $article->content, 'created_at' => $article->created_at, 'updated_at' => $article->updated_at, 'is_comments' => $article->comments_enable, 'category' => ['id' => $article->category->id, 'name' => $article->category->name, 'curl' => $article->category->curl]];
         foreach ($article->tags as $tag) {
             $data['tags'][] = ['id' => $tag->id, 'name' => $tag->name, 'curl' => $tag->curl];
         }
         return $data;
     });
 }
Пример #4
0
 public function getCommentsByIdArticle($id)
 {
     return Cache::store($this->store)->rememberForever($id, function () use($id) {
         $data = [];
         $comments_model = new CommentsModel();
         $comments = $comments_model->published()->commentsByArticleId($id)->orderByParam()->get();
         foreach ($comments as $coment) {
             $data[] = ['id' => $coment->id, 'user' => $coment->user, 'message' => $coment->message, 'answer' => $coment->answer];
         }
         return $data;
     });
 }
Пример #5
0
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $config = (new GeoCode\Config())->initFromArray(config('services.geo_code'));
     $this->app->singleton(GeoCode\Manager::class, function ($app) use($config) {
         $req = new GeoCode\Http\Guzzle(['base_uri' => $config->apiUrl, 'verify' => false]);
         return new GeoCode\Manager($config, $req, Cache::store($config->cacheDriver));
     });
     $this->app->bind(GeoCode\Response::class, function ($app) use($config) {
         return new GeoCode\Response($config->apiOutput, '');
     });
     $this->app->instance(GeoCode\Config::class, $config);
 }
Пример #6
0
 public function index()
 {
     $navFlag = 'blog';
     $newPosts = Cache::store('redis')->remember($this->indexPostsKey, 30, function () {
         $articles = [];
         $list = Wp::type('post')->status('publish')->orderBy('post_date', 'desc')->take(17)->get();
         foreach ($list as $item) {
             $articles[] = ['url' => $item->url, 'post_title' => $item->post_title, 'post_date' => $item->post_date->format('Y-m-d')];
         }
         return $articles;
     });
     return View('index/blog', compact('newPosts', 'navFlag'));
 }
Пример #7
0
 public function getAll()
 {
     return Cache::store('prevAll')->rememberForever($this->page, function () {
         //методанные
         $items['title'] = 'Главная';
         $items['keywords'] = 'блог, разработка, php, главная';
         $items['description'] = 'Главная страница блога начинающего backend разработчика. Заходите.';
         //превьюхи
         $articles = new Articles();
         $articles = $articles->published()->orderByParam()->with('tags', 'category')->paginate($this->countPage);
         //Превьюхи в нужном формате
         $items['articles'] = $this->createArrPreviews($articles);
         return $this->createLengthAwarePaginator($articles, $items);
     });
 }
Пример #8
0
 public function getCategoryNavigate()
 {
     return Cache::store($this->store)->rememberForever('menu:cat', function () {
         $cat_cl = new Categories();
         $categories = $cat_cl->getAllCategory();
         foreach ($categories as $key => $category) {
             $date[$key]['id'] = $category->id;
             $date[$key]['name'] = $category->name;
             $date[$key]['curl'] = $category->curl;
             //Получаем кол-во новостей в каждой категории
             $date[$key]['count_article'] = $category->getArticlesByCondition()->count();
         }
         return $date;
     });
 }
Пример #9
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $blockIps = Cache::get('block_ip', function () {
         $blockIps = BlockIp::all()->toArray();
         Cache::store('redis')->put('block_ip', $blockIps, 10);
         return $blockIps;
     });
     if ($blockIps) {
         foreach ($blockIps as $ip) {
             if (starts_with($request->getClientIp(), $ip['ip_address'])) {
                 abort(404);
             }
         }
     }
     return $next($request);
 }
Пример #10
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Cache::store('aside')->flush();
     $this->info('Asides cleared');
     Cache::store('prevAll')->flush();
     $this->info('Prev. cleared');
     Cache::store('prevCat')->flush();
     $this->info('Prev./cat. cleared');
     Cache::store('prevTag')->flush();
     $this->info('Prev./tag. cleared');
     Cache::store('article')->flush();
     $this->info('Articles cleared');
     Cache::store('comments')->flush();
     $this->info('Comments cleared');
     $this->info('All automatic cache cleared');
 }
Пример #11
0
 /**
  * Github上提交版本历史
  * @method POST
  * @return string
  */
 public function gitCommitHistory()
 {
     $client = new Client(['base_uri' => 'https://api.github.com/']);
     $uri = 'repos/tanteng/tanteng.me/commits';
     $query['client_id'] = Config::get('github.client_id');
     $query['client_secret'] = Config::get('github.client_secret');
     try {
         $result = Cache::store('redis')->remember('git.commit.history', 60, function () use($client, $uri, $query) {
             return $client->get($uri, $query)->getBody()->getContents();
         });
     } catch (ConnectException $e) {
         return json_encode(['result' => 1001, 'msg' => '请求超时!', 'data' => $e->getMessage()]);
     }
     $result = json_decode($result, true);
     $commitHistory = [];
     foreach ($result as $item) {
         $commitHistory[] = ['message' => $item['commit']['message'], 'datetime' => date('Y-m-d H:i:s', strtotime($item['commit']['committer']['date']))];
     }
     return json_encode(['result' => 0, 'msg' => '请求成功!', 'data' => $commitHistory]);
 }
Пример #12
0
 /**
  * Assign dependencies.
  */
 public function __construct()
 {
     $this->cache = Cache::store();
 }
Пример #13
0
 public function flushCache($store)
 {
     Cache::store($store)->flush();
 }