本文整理汇总了PHP中Illuminate\Contracts\Cache\Repository::put方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::put方法的具体用法?PHP Repository::put怎么用?PHP Repository::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Cache\Repository
的用法示例。
在下文中一共展示了Repository::put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* @return string Access token
*/
public function authenticate()
{
if (!$this->repository->has('brightcove.bearer')) {
$this->repository->put('brightcove.bearer', $this->brightcove->authenticate(), $this->duration);
}
return $this->repository->get('brightcove.bearer');
}
示例2: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, $data, $lifeTime = false)
{
if (!$lifeTime) {
return $this->cache->forever($id, $data);
}
return $this->cache->put($id, $data, $lifeTime);
}
示例3: put
/**
* setter
*
* @param string $key key name
* @param mixed $value the value
* @param int $minutes expire time
* @return void
*/
public function put($key, $value, $minutes = null)
{
if ($minutes == null) {
$minutes = $this->minutes;
}
$this->cache->put($key, $value, $minutes);
}
示例4: getNews
public function getNews()
{
$key = 'boomcms.news';
return $this->cache->get($key, function () use($key) {
$response = json_decode(@file_get_contents($this->newsUrl));
$news = $response->news ?? [];
$this->cache->put($key, $news, 3600);
return $news;
});
}
示例5: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(Cache $cache)
{
$this->info('Calculating stats >>>>>');
$expiresAt = Carbon::now()->addMinutes(10);
$tickets = Ticket::withTrashed()->get();
$openTickets = $tickets->filter(function ($ticket) {
return !$ticket->trashed();
});
$cache->put('tickets.open', $openTickets->count(), $expiresAt);
$cache->put('tickets.total', $tickets->count(), $expiresAt);
$this->info('Calculation done and results are cached');
}
示例6: performRealTimeQuery
/**
* Query the Google Analytics Real Time Reporting Service with given parameters.
*
* @param int $id
* @param string $metrics
* @param array $others
*
* @return mixed
*/
public function performRealTimeQuery($id, $metrics, array $others = [])
{
$realTimeCacheName = $this->determineRealTimeCacheName(func_get_args());
if ($this->useRealTimeCache() && $this->cache->has($realTimeCacheName)) {
return $this->cache->get($realTimeCacheName);
}
$googleAnswer = $this->service->data_realtime->get($id, $metrics, $others);
if ($this->useRealTimeCache()) {
$this->cache->put($realTimeCacheName, $googleAnswer, Carbon::now()->addSeconds($this->realTimeCacheLifeTimeInSeconds));
}
return $googleAnswer;
}
示例7: run
/**
* Run the given event.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return mixed
*
* @throws \Exception
*/
public function run(Container $container)
{
if ($this->description) {
$this->cache->put($this->mutexName(), true, 1440);
}
try {
$response = $container->call($this->callback, $this->parameters);
} finally {
$this->removeMutex();
}
parent::callAfterCallbacks($container);
return $response;
}
示例8: save
/**
* {@inheritdoc}
*/
public function save(CacheItemInterface $item)
{
$expiresAt = $this->getExpiresAt($item);
if (!$expiresAt) {
try {
$this->repository->forever($item->getKey(), serialize($item->get()));
} catch (Exception $exception) {
return false;
}
return true;
}
$now = new DateTimeImmutable('now', $expiresAt->getTimezone());
$seconds = $expiresAt->getTimestamp() - $now->getTimestamp();
$minutes = (int) floor($seconds / 60.0);
if ($minutes <= 0) {
$this->repository->forget($item->getKey());
return false;
}
try {
$this->repository->put($item->getKey(), serialize($item->get()), $minutes);
} catch (Exception $exception) {
return false;
}
return true;
}
示例9: load
protected function load()
{
// load from cache
if ($this->cache) {
$map = $this->cache->get('vat-rates');
}
// fetch from jsonvat.com
if (empty($map)) {
$map = $this->fetch();
// store in cache
if ($this->cache) {
$this->cache->put('vat-rates', $map, 86400);
}
}
return $map;
}
示例10: cacheCountBetween
/**
* Caches count between if cacheKey is present
*
* @param int $count
* @param Carbon $from
* @param Carbon $until
* @param string $locale
* @param string $cacheKey
*/
protected function cacheCountBetween($count, Carbon $from, Carbon $until, $locale, $cacheKey)
{
// Cache only if cacheKey is present
if ($cacheKey && $until->timestamp < Carbon::now()->timestamp) {
$key = $this->makeBetweenCacheKey($from, $until, $locale, $cacheKey);
$this->cache->put($key, $count, 525600);
}
}
示例11: handle
/**
* Handle the command.
*
* @param Repository $cache
* @param Request $request
* @param UserAuthenticator $authenticator
* @param SettingRepositoryInterface $settings
* @param ThrottleSecurityCheckExtension $extension
* @return bool
*/
public function handle(Repository $cache, Request $request, UserAuthenticator $authenticator, SettingRepositoryInterface $settings, ThrottleSecurityCheckExtension $extension)
{
$maxAttempts = $settings->value('anomaly.extension.throttle_security_check::max_attempts', 5);
$lockoutInterval = $settings->value('anomaly.extension.throttle_security_check::lockout_interval', 1);
$throttleInterval = $settings->value('anomaly.extension.throttle_security_check::throttle_interval', 1);
$attempts = $cache->get($extension->getNamespace('attempts:' . $request->ip()), 1);
$expiration = $cache->get($extension->getNamespace('expiration:' . $request->ip()));
if ($expiration || $attempts >= $maxAttempts) {
$cache->put($extension->getNamespace('attempts:' . $request->ip()), $attempts + 1, $throttleInterval);
$cache->put($extension->getNamespace('expiration:' . $request->ip()), time(), $lockoutInterval);
$authenticator->logout();
// Just for safe measure.
return $this->dispatch(new MakeResponse());
}
$cache->put($extension->getNamespace('attempts:' . $request->ip()), $attempts + 1, $throttleInterval);
return true;
}
示例12: getProfileFromWatson
/**
* Get Full Insights From Watson API.
*
* @throws \FindBrok\WatsonBridge\Exceptions\WatsonBridgeException
*
* @return \Illuminate\Support\Collection
*/
public function getProfileFromWatson()
{
//We have the request in cache and cache is on
if ($this->cacheIsOn() && $this->cache->has($this->getContainer()->getCacheKey())) {
//Return results from cache
return $this->cache->get($this->getContainer()->getCacheKey());
}
//Cross the bridge
$response = $this->makeBridge()->post('v2/profile', $this->getContainer()->getContentsForRequest());
//Decode profile
$profile = collect(json_decode($response->getBody()->getContents(), true));
//Cache results if cache is on
if ($this->cacheIsOn()) {
$this->cache->put($this->getContainer()->getCacheKey(), $profile, $this->cacheLifetime());
}
//Return profile
return $profile;
}
示例13: run
/**
* Run the given event.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function run(Container $container)
{
if ($this->withoutOverlapping) {
$this->cache->put($this->mutexName(), true, 1440);
}
if ($this->runInBackground) {
$this->runCommandInBackground();
} else {
$this->runCommandInForeground($container);
}
}
示例14: handle
public function handle(RateFetcher $source, Cache $cache)
{
$rates = $source->getUsdRates($this->date);
if (!count($rates)) {
throw new ForexException('received empty array of rates');
}
$cacheKey = $this->date ? $this->date->format('Y-m-d') : 'live';
// save rates for two hours to main cache
$cache->put(ForexService::RATE_CACHE_KEY_PREFIX . $cacheKey, $rates, 120);
// save rates indefinitely for backup cache
$cache->forever(ForexService::BACKUP_CACHE_KEY_PREFIX . $cacheKey, $rates);
}
示例15: backupColumn
/**
* Backup the field type column to cache.
*
* @param Blueprint $table
*/
public function backupColumn(Blueprint $table)
{
// Skip if no column type.
if (!$this->fieldType->getColumnType()) {
return;
}
// Skip if the column doesn't exist.
if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
return;
}
// Back dat data up.
$results = $this->connection->table($table->getTable())->select(['id', $this->fieldType->getColumnName()])->get();
$this->cache->put(__CLASS__ . $this->fieldType->getColumnName(), $results, 10);
}