Ejemplo n.º 1
0
 /**
  * Cache the key value till 12am
  *
  * @param  string  $key
  * @param  mixed  $value
  * @return void
  */
 public static function put($key, $value)
 {
     $today = strtotime(date('Ymd'));
     $key = "{$today}.{$key}";
     $minutes = (int) date('i');
     $total_minutes_today = date('G') * 60 + $minutes;
     $minutes_till_midnight = 1440 - $total_minutes_today;
     static::$cache->put($key, $value, $minutes_till_midnight);
 }
Ejemplo n.º 2
0
 /**
  * Handles authenticating that a user/character is still valid.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function postAuthorized()
 {
     // Get the neccessary headers from the request.
     $service = $this->request->header('service', false);
     $username = $this->request->header('username', '');
     $character = $this->request->header('character', '');
     $this->log->info('A service is attempting to validate a user.', ['username' => $username, 'character' => $character, 'service' => $service]);
     // Verify that the external service exists in the configuration.
     if (!$service || !$this->config->get("addon.auth.{$service}")) {
         $this->log->info(self::ERROR_INVALID_EXTERNAL_SERVICE, ['service' => $service]);
         return $this->failure(self::ERRNO_INVALID_EXTERNAL_SERVICE, self::ERROR_INVALID_EXTERNAL_SERVICE);
     }
     // Check the cache first so the api isn't hammered too badly.
     $key = 'auth:session:' . sha1("{$service}:{$username}");
     if ($this->cache->has($key)) {
         $this->log->info('Returning the cached authorization result.');
         return $this->cache->get($key);
     }
     // Attempt to find the requested user.
     $identifier = filter_var($username, FILTER_VALIDATE_EMAIL) ? 'email' : 'name';
     $user = $this->users->where($identifier, $username)->first() ?: false;
     if (!$user) {
         $this->log->info(self::ERROR_USER_NOT_FOUND);
         return $this->failure(self::ERRNO_USER_NOT_FOUND, self::ERROR_USER_NOT_FOUND);
     }
     // Get and cache the response for 15 minutes.
     $response = $this->getLoginResult($user, $service, $character);
     $this->cache->put($key, $response, $this->carbon->now()->addMinutes(15));
     return $response;
 }
Ejemplo n.º 3
0
 public function image(Repository $cache, $id)
 {
     if ($cache->has($id)) {
         return $cache->get($id);
     }
     $card = base64_encode(file_get_contents('http://magiccards.info/scans/en/ori/' . $id . '.jpg'));
     $cache->put($id, $card, 60);
     return $card;
 }
Ejemplo n.º 4
0
 /**
  * Save a cached view if caching is enabled.
  *
  * @param  \Illuminate\Http\Response  $response
  * @return void
  */
 protected function saveCachedView(Response $response)
 {
     if (config('sitemap.cache_enabled')) {
         $key = $this->getCacheKey();
         $content = $response->getOriginalContent()->render();
         if (!$this->cache->get($key)) {
             $this->cache->put($key, $content, config('sitemap.cache_length'));
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Generate thumbnail.
  *
  * @param $src
  * @param $width
  * @param $height
  *
  * @throws \RuntimeException
  * @return Thumbnail
  */
 public function make($src, $width, $height)
 {
     if ($src === null || $width === null && $height === null) {
         throw new \RuntimeException();
     }
     $key = md5($src . 'w' . $width . 'h' . $height);
     if (!($image = $this->cache->get($key))) {
         $image = $this->image->make($src);
         $image->resize($width, $height, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         if ($width === null) {
             $width = $image->getWidth();
         }
         if ($height === null) {
             $height = $image->getHeight();
         }
         $image->resizeCanvas($width, $height, 'center', false, 'ffffff');
         $image = (string) $image->encode('jpg');
         $this->cache->put($key, $image, $this->lifetime);
     }
     return new Thumbnail($key, $image, $this->expires(), 'image/jpeg');
 }
Ejemplo n.º 6
0
 /**
  * Store an item in the cache.
  *
  * @param string $key
  * @param mixed $value
  * @param \DateTime|int $minutes
  * @return void 
  * @static 
  */
 public static function put($key, $value, $minutes)
 {
     \Illuminate\Cache\Repository::put($key, $value, $minutes);
 }
Ejemplo n.º 7
0
 /**
  * Store an item in the cache.
  *
  * @param  mixed  $key
  * @param  mixed  $value
  * @param  \DateTime|int  $minutes
  * @return void
  */
 public function put($key, $value, $minutes)
 {
     if (is_array($key) && is_array($value)) {
         $this->putMany(array_combine($key, $value), $minutes);
     } else {
         parent::put($key, $value, $minutes);
     }
 }
 /**
  * @param string                    $key
  * @param \Illuminate\Http\Response $response
  * @param \DateTime|int             $minutes
  */
 public function put($key, $response, $minutes)
 {
     $this->cache->put($key, $this->responseSerializer->serialize($response), $minutes);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     return $this->cache->put($sessionId, $data, $this->minutes);
 }
Ejemplo n.º 10
0
 /**
  * 保存验证码到缓存中
  * @param string $mobile
  * @param string $code
  * @param string $bag
  * @return \Illuminate\Cache\void
  */
 public function putCodeToCache($mobile, $code, $bag)
 {
     $key = $this->getCacheKey($mobile, $bag);
     return $this->store->put($key, $code, $this->cacheMinutes);
 }
Ejemplo n.º 11
0
 /**
  * Setter for token
  *
  * @param string $key
  * @param string $value
  * @param int $duration
  */
 public function setToken($key, $value, $duration = 60)
 {
     $this->cache->put('reactor.tokens.' . $key, $value, $duration);
 }
Ejemplo n.º 12
0
 /**
  * @param $content
  * @return mixed
  */
 public function put($key, $content)
 {
     if ($this->enabled) {
         return $this->cache->put($key, $content, $this->getCacheLifetime());
     }
 }
 /**
  * Updates the inverse index for the given cache key.
  *
  * @param  string             $key
  * @param  \DateTime|int|null $minutes
  */
 protected function updateInverseIndex($key, $minutes = null)
 {
     $this->setKeywordsOperation(true);
     $keywordsState = $this->determineKeywordsState($key);
     $inverseIndexKey = $this->generateInverseIndexKey($key);
     if (empty($keywordsState['new'])) {
         parent::forget($inverseIndexKey);
     } elseif ($keywordsState['old'] != $keywordsState['new']) {
         $newInverseIndex = array_values($keywordsState['new']);
         is_null($minutes) ? parent::forever($inverseIndexKey, $newInverseIndex) : parent::put($inverseIndexKey, $newInverseIndex, $minutes);
     }
     $this->setKeywordsOperation(false);
 }
Ejemplo n.º 14
0
 /**
  * Store an item in the cache.
  *
  * @param  string        $key
  * @param  mixed         $value
  * @param  \DateTime|int $minutes
  *
  * @return void
  */
 public function put($key, $value, $minutes)
 {
     if ($this->enabled) {
         $this->cache->put($key, $value, $minutes);
     }
 }
Ejemplo n.º 15
0
 /**
  * @param $result
  */
 public function storeResultInCache($result)
 {
     $this->cache->put($this->actualQueryHash, $result, $this->cacheLifeTime);
 }