本文整理汇总了PHP中Illuminate\Cache\Repository类的典型用法代码示例。如果您正苦于以下问题:PHP Repository类的具体用法?PHP Repository怎么用?PHP Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* 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();
}
示例2: search
public function search(Repository $cache, $search = 'enchantment')
{
$client = new Client(config('algolia.connections.main.id'), config('algolia.connections.main.key'));
//if ($cache->has('origins.'. $search)) {
// $cards = $cache->get($search);
//} else {
$index = $client->initIndex(config('algolia.index'));
$index->setSettings(['attributesForFaceting' => ['colors', 'multiverseid']]);
$cards = $index->search($search, ['facets' => '*', 'facetFilters' => 'colors:Green'])['hits'];
foreach ($cards as $index => $card) {
if (isset($card['manaCost'])) {
$cards[$index]['manaCost'] = preg_replace('/{(.)}/', '<img src="/images/blank.png" id="$1" />', $card['manaCost']);
}
}
$cache->forever($search, $cards);
//}
$this->setJavascriptData(compact('cards'));
}
示例3: save
public function save()
{
// New and changed keys
$changed = array_diff_assoc($this->data, $this->original);
$insertValues = array();
foreach ($changed as $name => $value) {
if (!array_key_exists($name, $this->original)) {
$insertValues[] = array('conf_name' => $name, 'conf_value' => $value);
unset($changed[$name]);
}
}
if (!empty($insertValues)) {
$this->database->table('config')->insert($insertValues);
}
foreach ($changed as $name => $value) {
$this->database->table('config')->where('conf_name', '=', $name)->update(array('conf_value' => $value));
}
// Deleted keys
$deletedKeys = array_keys(array_diff_key($this->original, $this->data));
if (!empty($deletedKeys)) {
$this->database->table('config')->whereIn('conf_name', $deletedKeys)->delete();
}
// No need to cache old values anymore
$this->original = $this->data;
// Delete the cache so that it will be regenerated on the next request
$this->cache->forget('fluxbb.config');
}
示例4: cache
/**
* Get info from a specify url and cache that using laravel cache manager.
*
* @param string $url
* @param null|array $options
* @return mixed
*/
public function cache($url, array $options = null)
{
$lifetime = array_get($options, 'lifetime', 60);
array_forget($options, 'lifetime');
$self = $this;
return $this->cache->remember($url, $lifetime, function () use($self, $url, $options) {
return $self->get($url, $options);
});
}
示例5: put
/**
* 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);
}
示例6: format
/**
* {@inheritdoc}
*/
protected function format($string)
{
if (!$this->watch) {
$key = 'js.' . sha1($string);
$string = $this->cache->rememberForever($key, function () use($string) {
return $this->minify($string);
});
}
return $string . ";\n";
}
示例7: cached
/**
* Returns the cached content if NOT running locally.
*
* @param string $key
* @param mixed $value
* @param int $time
* @return mixed
*/
private function cached($key, $value, $time = 5)
{
if (App::environment('local') === false) {
return $this->cache->remember($key, $time, function () use($value) {
return $value;
});
} else {
return $value;
}
}
示例8: getColumnsOnCache
/**
* To get all columns on caching
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return array
*/
protected function getColumnsOnCache(Model $model)
{
/**
* In normal scenario tables and columns often is not changed.
* Therefore every time it is not need to access the database for knowing
* columns name. We don't want make preoccupy/busy to the database.
*/
$fullKey = $this->getFullName($model);
return $this->cache->remember($fullKey, $this->getRememberTime(), function () use($model) {
return $this->builder->getColumnListing($model->getTable());
});
}
示例9: postAuthorized
/**
* 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;
}
示例10: get
/**
* 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);
}
示例11: save
/**
* {@inheritdoc}
*/
public function save($key, CacheEntry $data)
{
try {
$lifeTime = $data->getTTL();
if ($lifeTime === 0) {
return $this->cache->forever($key, serialize($data));
} else {
if ($lifeTime > 0) {
return $this->cache->add($key, serialize($data), $lifeTime);
}
}
} catch (\Exception $ignored) {
// No fail if we can't save it the storage
}
return false;
}
示例12: getSubTitle
/**
* Get the page sub title
*
* @param string $page
* @return string
*/
public function getSubTitle($page)
{
$pageFile = $this->getDocumentationPath() . "/{$page}.md";
return $this->cache->rememberForever("doc_page_{$pageFile}_sub-title", function () use($pageFile) {
$data = $this->parser->parse($this->finder->get($pageFile));
return $data->get('subtitle');
});
}
示例13: getInstalledThemes
/**
* 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();
}
示例14: makeCacheKey
/**
* 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;
}
示例15: testShouldReturnNullFlushRecord
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'));
}