Ejemplo n.º 1
0
 /**
  * @param Builder $qb
  * @param array $attributes
  * @return LengthAwarePaginator|Collection|null
  */
 public function tryFetchResultFromCache(Builder $qb, array $attributes = [])
 {
     $this->generateQueryHashFromQueryBuilder($qb, $attributes);
     if ($this->cache->has($this->actualQueryHash)) {
         return $this->cache->get($this->actualQueryHash);
     }
     return null;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $types = $this->config->get('assets.types');
     $oldVersion = $this->cache->get('laravel-asset-versioning.version');
     $version = Carbon::now()->timestamp;
     $this->updateConfigVersion($version);
     $this->unlinkOldDirectories($types, $oldVersion);
     $this->createDistDirectories($types, $version);
 }
 public function testShouldReturnNullFlushRecord()
 {
     $this->repository->add('memcached-testing', 'couchbase', 60);
     $this->repository->decrement('memcached-testing-decrement', 100);
     $this->repository->increment('memcached-testing-increment', 100);
     $this->repository->flush();
     $this->assertNull($this->repository->get('memcached-testing'));
     $this->assertNull($this->repository->get('memcached-testing-decrement'));
     $this->assertNull($this->repository->get('memcached-testing-increment'));
 }
 /**
  * {@inheritdoc}
  */
 public function fetch($key)
 {
     try {
         $cache = unserialize($this->cache->get($key));
         if ($cache instanceof CacheEntry) {
             return $cache;
         }
     } catch (\Exception $ignored) {
         return;
     }
     return;
 }
Ejemplo n.º 5
0
 /**
  * Verify the existence of the given user token.
  *
  * @param string $token
  *
  * @return \Fahita\Contracts\UserInterface|null
  */
 public function loginWithToken($token)
 {
     if ($this->verifyToken($token)) {
         $id = $this->cache->get($this->getCacheKey($token));
         $attributes = $this->redis->hgetall('users:' . $id);
         $user = (new User())->newInstance($attributes, true);
         // creating a new instance does not include the record id
         // but we want it, so we force fill it to fulfill it.
         $user->forceFill($attributes);
         return $this->login($user);
     }
 }
Ejemplo n.º 6
0
 /**
  * Retrieve an item from the cache by key.
  *
  * @param  mixed  $key
  * @param  mixed  $default
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if (is_array($key)) {
         return $this->getMany($key, $default);
     }
     return parent::get($key, $default);
 }
Ejemplo n.º 7
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.º 8
0
 /**
  * Retrieve an item from the cache by key. If the item is about to expire soon,
  * extend the existing cache entry (for other requests) before returning the item
  *
  * @param  string  $key
  * @param  mixed   $default
  * @return mixed
  */
 public function get($key, $default = null)
 {
     while ($this->cacheFlagExists($key)) {
         sleep($this->sleep);
     }
     return parent::get($key, $default);
 }
Ejemplo n.º 9
0
 /**
  * Retrives the installed themes from the cache.
  *
  * If the cahce entry doesn't exist then it is created.
  *
  * @return array
  */
 public function getInstalledThemes()
 {
     $installed = $this->cache->get($this->cacheKey);
     if ($installed !== null) {
         return $installed;
     }
     return $this->findAndInstallThemes();
 }
 /**
  * make a cache key
  *
  * @param string $key
  * @param string $prefix
  * @return string
  */
 private function makeCacheKey($key, $prefix = '')
 {
     $key = md5($prefix . $key);
     $keys = $this->cache->get(self::CACHE_KEYS_KEY, []);
     $keys[$key] = $key;
     $this->cache->forever(self::CACHE_KEYS_KEY, $keys);
     return $key;
 }
Ejemplo n.º 11
0
 /**
  * @return Realm
  */
 public function getRealmData()
 {
     $that = $this;
     return $this->cache->get('ekko:static:realm', function () use($that) {
         $data = $this->ekko->data()->getRealm();
         $that->cache->add('ekko:static:realm', $data, 60 * 24 * 7);
         return $data;
     });
 }
Ejemplo n.º 12
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.º 13
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.º 14
0
 /**
  * @param $matchId
  *
  * @return Match
  */
 public function getMatch($matchId)
 {
     $that = $this;
     $cachKey = 'match:' . $matchId;
     return $this->cache->get($cachKey, function () use($that, $cachKey, $matchId) {
         $match = $that->ekko->matches()->getMatch($matchId, true);
         $match = $that->setStaticData($match);
         $that->cache->put('match:' . $matchId, $match, 3600);
         return $match;
     });
 }
Ejemplo n.º 15
0
 public function replaceVersion($path)
 {
     $version = $this->cache->get('laravel-asset-versioning.version');
     $file = explode('.', $path);
     $extension = $file[count($file) - 1];
     $types = $this->config->get('assets.types.' . $extension);
     if (isset($types['origin_dir'])) {
         $types = [$types];
     }
     foreach ((array) $types as $type) {
         if (!$type) {
             continue;
         }
         if (!preg_match("#^\\/?" . $type['origin_dir'] . "#", $path)) {
             continue;
         }
         $resource = str_replace($type['origin_dir'], $type['dist_dir'] . '/' . $version, $path);
         $this->addHTTP2Link($resource, $extension);
         return $resource;
     }
     return $path;
 }
Ejemplo n.º 16
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.º 17
0
 /**
  * Handle the form.
  *
  * @param Repository $cache
  * @param Redirector $redirect
  * @param            $key
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handle(Repository $cache, Redirector $redirect, $key)
 {
     $parameters = $cache->get('form::' . $key);
     $criteria = $this->dispatch(new GetFormCriteria($parameters));
     /* @var FormBuilder $builder */
     $builder = $criteria->builder();
     $response = $builder->build()->post()->getFormResponse();
     $builder->flash();
     if ($response && $response->getStatusCode() !== 200) {
         return $response;
     }
     if ($builder->hasFormErrors()) {
         return $redirect->back();
     }
     return $response ?: $redirect->back();
 }
Ejemplo n.º 18
0
 /**
  * {@inheritDoc}
  */
 public function read($sessionId)
 {
     return $this->cache->get($sessionId, '');
 }
Ejemplo n.º 19
0
 /**
  * Get the last code change timestamp, or null.
  *
  * @return int|null
  */
 protected function getLastCodeChangeTimestamp()
 {
     if ($this->cache) {
         return $this->cache->get('illuminate:changed');
     }
 }
Ejemplo n.º 20
0
 /**
  * load
  *
  * @return array
  */
 protected function load()
 {
     $cachedJsonString = $this->cache->get($this->cacheKey);
     $dataArr = json_dec($cachedJsonString, true);
     return $dataArr;
 }
Ejemplo n.º 21
0
 /**
  * Retrieve an item from the cache by key.
  *
  * @param  string $key
  * @param  mixed  $default
  *
  * @return mixed
  */
 public function get($key, $default = null)
 {
     return $this->enabled ? $this->cache->get($key, $default) : $default;
 }
Ejemplo n.º 22
0
 /**
  * @param $page_id
  * @return string
  */
 private function generatePageCacheKey($page_id)
 {
     $last_edit_key = $this->cache->get('last_page_edit_time', 0);
     return $last_edit_key . '_' . 'page-' . $page_id . '-' . md5(var_export($this->getInput(), true));
 }
 /**
  * Retrieve an item from the cache by key.
  *
  * @param  string $key
  * @param  mixed  $default
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if (!$this->operatingOnKeywords()) {
         $this->resetCurrentKeywords();
     }
     return parent::get($key, $default);
 }
 /**
  * @param string $key
  *
  * @return \Illuminate\Http\Response
  */
 public function get($key)
 {
     return $this->responseSerializer->unserialize($this->cache->get($key));
 }
 /**
  * getCachedSiteInstanceRoutes
  *
  * @param string $siteKey site key to get instance routes
  *
  * @return mixed
  */
 public function getCachedSiteInstanceRoutes($siteKey)
 {
     $keyString = $this->getSiteCacheKeyString($siteKey);
     if ($this->isExistCachedSiteInstanceRoutes($siteKey)) {
         return unserialize($this->cache->get($keyString));
     } else {
         throw new NotFoundInstanceRouteException();
     }
 }
Ejemplo n.º 26
0
 /**
  * 获取
  * @param string $mobile
  * @param string $bag
  */
 public function getCodeFromCache($mobile, $bag, $default = null)
 {
     $key = $this->getCacheKey($mobile, $bag);
     $cache = $this->store->get($key);
     return $cache ?: $this->value($default);
 }
Ejemplo n.º 27
0
 /**
  * Getter for token
  *
  * @param string $key
  * @return string|null
  */
 public function getToken($key)
 {
     return $this->cache->get('reactor.tokens.' . $key, null);
 }
Ejemplo n.º 28
0
 /**
  * Get a chunk from the cache.
  *
  * @param type        $type
  * @param type        $slotname
  * @param PageVersion $version
  *
  * @return mixed
  */
 public function getFromCache($type, $slotname, PageVersion $version)
 {
     $key = $this->getCacheKey($type, $slotname, $version);
     return $this->cache->get($key, false);
 }
Ejemplo n.º 29
0
 /**
  * Retrieve an item from the cache by key.
  *
  * @param string $key
  * @param mixed $default
  * @return mixed 
  * @static 
  */
 public static function get($key, $default = null)
 {
     return \Illuminate\Cache\Repository::get($key, $default);
 }
Ejemplo n.º 30
0
 /**
  * Get the last queue restart timestamp, or null.
  *
  * @return int|null
  */
 protected function getTimestampOfLastQueueRestart()
 {
     if ($this->cache) {
         return $this->cache->get('illuminate:queue:restart');
     }
 }