private function _fetchDataset($filter)
 {
     return Cache::get($this->key, function () use($filter) {
         Cache::add($this->key, $data = $this->_getDataPartialRecursive($filter), 60);
         return $data;
     });
 }
Esempio n. 2
0
 /**
  * Return the content of the Site Map
  */
 public function getSiteMap()
 {
     if (Cache::has('site-map')) {
         return Cache::get('site-map');
     }
     $siteMap = $this->buildSiteMap();
     Cache::add('site-map', $siteMap, 120);
     return $siteMap;
 }
Esempio n. 3
0
 /**
  * Return the content of the RSS feed
  */
 public function getRSS()
 {
     if (Cache::has('rss-feed')) {
         return Cache::get('rss-feed');
     }
     $rss = $this->buildRssData();
     Cache::add('rss-feed', $rss, 120);
     return $rss;
 }
Esempio n. 4
0
 public function index() : string
 {
     if (Cache::has('rss-feed')) {
         return Cache::get('rss-feed');
     }
     $rss = $this->assembleFeed();
     Cache::add('rss-feed', $rss, 120);
     return $rss;
 }
 protected function incrementLoginAttempts(Request $request)
 {
     $key = $this->getLoginAttemptsKey($request);
     if (!Cache::has($key)) {
         Cache::add($key, 1, static::LOGIN_LOCKOUT_MINUTES);
         return 1;
     }
     return (int) Cache::increment($key);
 }
Esempio n. 6
0
 public static function getHot()
 {
     if (!Cache::has(GlobalVar::$HOT_CACHE)) {
         $bili_util = new BiliUtil();
         $hot_list = $bili_util->getHot();
         Cache::add(GlobalVar::$HOT_CACHE, $hot_list, 60 * 5);
     } else {
         $hot_list = Cache::get(GlobalVar::$HOT_CACHE);
     }
     return $hot_list;
 }
Esempio n. 7
0
 private function setInCache($name, $data, $cache = null)
 {
     if ($this->config['enable_cache']) {
         $lifeTime = is_null($cache) ? $this->config['cache_live_time'] : $cache;
         $created_at = Carbon::now();
         $data['cache']['enabled'] = true;
         $data['cache']['created_at'] = $created_at->timestamp;
         $data['cache']['end_at'] = $created_at->addMinutes($lifeTime)->timestamp;
         Cache::add($name, $data, $lifeTime);
     }
 }
Esempio n. 8
0
 /**
  * 获取热门文章列表
  * @param $n        取出数量
  * @return array
  */
 public static function getHotArticleList($n)
 {
     if (empty($articles = Cache::get(self::REIDS_HOT_ARTICLE_CACHE))) {
         $articles = [];
         $ids = ArticleStatus::limit($n)->orderBy('view_number', 'desc')->get();
         foreach ($ids as $v) {
             if ($article = self::getArticleModelByArticleId($v->art_id)) {
                 array_push($articles, $article);
             }
         }
         Cache::add(self::REIDS_HOT_ARTICLE_CACHE, $articles, config('site')['redis_cache_time']);
     }
     return $articles;
 }
Esempio n. 9
0
 /**
  * Increment the login attempts for the user.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return int
  */
 protected function incrementLoginAttempts(Request $request)
 {
     Cache::add($key = $this->getLoginAttemptsKey($request), 1, 1);
     return (int) Cache::increment($key);
 }
Esempio n. 10
0
 public function createCache()
 {
     $this->hasError();
     Cache::add($this->qdn->slug, user()->employee->name, 5);
     return $this;
 }
Esempio n. 11
0
 /**
  * Get a RateSeries (not supported by Yahoo)
  *
  * @param type $from
  * @param type $to
  * @param type $dateStart
  * @param type $dateEnd
  *
  *  @return object returns a GuzzleHttp\Client object.
  */
 public function getRateSeries($from, $to, $dateStart, $dateEnd)
 {
     if ($this->settings['enable-cache']) {
         $api = $this->settings['api-source'];
         if (Cache::has("CConverter{$from}{$to}{$dateStart}{$dateEnd}")) {
             $result = Cache::get("CConverter{$from}{$to}{$dateStart}{$dateEnd}");
             $this->fromCache = true;
             if (Config::get('CConverter.enable-log')) {
                 Log::debug("Got currency rates from cache: CConverter{$from}{$to}{$dateStart}{$dateEnd}");
             }
         } else {
             if ($api === 'yahoo') {
                 return null;
             } else {
                 if ($api === 'openexchange') {
                     return null;
                     //$result = $this->openExchange($base);
                 } else {
                     if ($api === 'jsonrates') {
                         $result = $this->jsonRatesTimeSeries($from, $to, $dateStart, $dateEnd);
                     }
                 }
             }
             Cache::add("CConverter{$from}{$to}{$dateStart}{$dateEnd}", $result, $this->settings['cache-min']);
             $this->fromCache = false;
             if (Config::get('CConverter.enable-log')) {
                 Log::debug('Added new currency rates to cache: CConverter' . $api . $from . $to . $dateStart . $dateEnd . ' - for ' . $this->settings['cache-min'] . ' min.');
             }
         }
     } else {
         if ($api === 'yahoo') {
             return null;
         } else {
             if ($api === 'openexchange') {
                 return null;
                 //$result = $this->openExchange($base);
             } else {
                 if ($api === 'jsonrates') {
                     $result = $this->jsonRatesTimeSeries($from, $to, $dateStart, $dateEnd);
                 }
             }
         }
         $this->fromCache = false;
     }
     return $result;
 }
Esempio n. 12
0
 /**
  * 分区信息
  *
  * @return $this
  */
 public function getList()
 {
     try {
         $tid = Input::get('tid', 0);
         $page = Input::get('page', 1);
         $order = Input::get('order', 'hot');
         $bili_util = new BiliUtil();
         if ($page == 1) {
             $cache_name = GlobalVar::$LIST_CACHE . $tid;
             if (!Cache::has($cache_name)) {
                 $back_json = $bili_util->getPageList($tid, $order, 1, GlobalVar::$PAGE_SIZE);
                 Cache::add($cache_name, $back_json, 60 * 60 * 2);
             } else {
                 $back_json = Cache::get($cache_name);
             }
         } else {
             $back_json = $bili_util->getPageList($tid, $order, $page, GlobalVar::$PAGE_SIZE);
         }
         $paginator = new Paginator($back_json['list'], $page);
         $paginator->setPath('/list');
         $sorts = CacheSetter::getSort();
         $hot = CacheSetter::getHot();
         return view('pusher.list')->with('sorts', $sorts)->with('list', $back_json['list'])->with("paginator", $paginator)->with('tid', $tid)->with('hots', $hot);
     } catch (Exception $e) {
         return view('pusher.error')->with('error_content', $e->getMessage());
     }
 }
 public function checkTotalQueueJobsVelocity($queue_velocity_params, $connection = null)
 {
     foreach ($queue_velocity_params as $queue_name => $velocity_params) {
         // echo "checking queue $queue_name.  Now is ".Carbon::now()."\n";
         $service_id = $this->service_prefix . "queue_velocity_" . $queue_name;
         try {
             $minumum_velocity = $velocity_params[0];
             $time_description = $velocity_params[1];
             $now = Carbon::now();
             $old_time = Carbon::parse('-' . $time_description);
             $seconds_to_check = $old_time->diffInSeconds($now);
             $total_size_now = $this->getTotalQueueJobs($queue_name, $connection);
             $total_size_past = $this->getTotalQueueJobsInThePast($queue_name, $old_time);
             // echo "$queue_name \$now={$now} \$old_time={$old_time} \$total_size_now=".json_encode($total_size_now, 192)." \$total_size_past=".json_encode($total_size_past, 192)."\n";
             // cache $total_size_now
             $expires_at_time = $now->copy()->addSeconds($seconds_to_check)->addMinutes(10);
             $key = 'qTotalJobs_' . $queue_name . '_' . $now->format('Ymd_Hi');
             // echo "PUT key={$key} value=".json_encode($total_size_now, 192)." Expires at ".$expires_at_time."\n";
             Cache::add($key, $total_size_now, $expires_at_time);
             if ($total_size_past === null) {
                 // not enough information - pass for now
                 $this->consul_client->checkPass($service_id);
                 return;
             }
             try {
                 $actual_velocity = $total_size_now - $total_size_past;
                 // echo "$queue_name \$actual_velocity=$actual_velocity\n";
                 if ($actual_velocity >= $minumum_velocity) {
                     $this->consul_client->checkPass($service_id);
                 } else {
                     $this->consul_client->checkFail($service_id, "Queue {$queue_name} velocity was {$actual_velocity} in {$time_description}");
                 }
             } catch (Exception $e) {
                 Log::error($e->getMessage());
             }
         } catch (Exception $e) {
             try {
                 $this->consul_client->checkFail($service_id, $e->getMessage());
                 Log::error($e->getMessage());
             } catch (Exception $e) {
                 Log::error($e->getMessage());
             }
         }
     }
     return;
 }
Esempio n. 14
0
 public function set($key, $value)
 {
     Cache::add($key, $value, 5);
 }
Esempio n. 15
0
 /**
  * Execute a callback function with a lock.
  *
  * Takes a callback function as a parameter, and only execute that callback function
  * once the lock has been acquired, or a timeout has passed.
  *
  * @param string   $key            Cache key.
  * @param callback $callback       Callback function.
  * @param integer  $timeousSeconds Timeout seconds.
  * @static
  * @access public
  * @return void
  */
 public static function withLock($key, $callback, $timeousSeconds = 10)
 {
     $start = time();
     $acquiredLock = false;
     while (time() - $start < $timeousSeconds && !$acquiredLock) {
         $acquiredLock = Cache::add(self::lockKey($key), time(), 1);
         if (!$acquiredLock) {
             usleep(100000);
         }
     }
     call_user_func($callback);
     Cache::forget(self::lockKey($key));
 }
 protected function getTwitterFeed($feedname)
 {
     if (!Cache::has($feedname)) {
         if (strpos($feedname, 'Home')) {
             $timeline = Twitter::getHomeTimeline(array('screen_name' => Config::get('feeds.twitterScreenName'), 'count' => 3, 'format' => 'object'));
         } else {
             $timeline = Twitter::getUserTimeline(array('screen_name' => Config::get('feeds.twitterScreenName'), 'count' => 3, 'format' => 'object'));
         }
         Cache::add($feedname, $timeline, 60);
     }
     return Cache::get($feedname);
 }