本文整理汇总了PHP中Illuminate\Contracts\Cache\Repository::forever方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::forever方法的具体用法?PHP Repository::forever怎么用?PHP Repository::forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Cache\Repository
的用法示例。
在下文中一共展示了Repository::forever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, $data, $lifeTime = false)
{
if (!$lifeTime) {
return $this->cache->forever($id, $data);
}
return $this->cache->put($id, $data, $lifeTime);
}
示例2: check
public function check($value)
{
$result = false;
if ($this->store->has('captcha')) {
$captchaStore = $this->store->get('captcha');
$result = $captchaStore->check($value);
$this->store->forever('captcha', $captchaStore);
}
return $result;
}
示例3: recountForums
private function recountForums()
{
$this->info('Recounting forum counters...');
// We're calling the model directly to avoid caching issues
$forums = Forum::all();
foreach ($forums as $forum) {
// We need the topics later to calculate the post number and the last post
$topics = Topic::where('forum_id', '=', $forum->id)->orderBy('created_at', 'desc');
$forum->num_topics = $topics->count();
$numPosts = 0;
$lastPost = null;
$lastPostUser = null;
foreach ($topics->get() as $topic) {
$numPosts += $topic->num_posts;
// We can simply override this variable all the time.
// The topics are sorted so the last time we override this we have our last post
$lastPost = $topic->last_post_id;
$lastPostUser = $topic->lastPost->user_id;
}
$forum->num_posts = $numPosts;
$forum->last_post_id = $lastPost;
$forum->last_post_user_id = $lastPostUser;
$forum->save();
}
// Override our old cache to populate our new numbers
$this->cache->forever('forums.all', $forums);
// We could also recache this cache but the recount tool is already busy
// so probably better to leave it to the first user
$this->cache->forget('forums.index_tree');
$this->info('Done' . PHP_EOL);
}
示例4: 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;
}
示例5: getIndexTree
/**
* Get the forum tree for the index, consisting of root forums (categories), and one level of descendants.
*
* @param bool $checkPermissions
*
* @return mixed
*/
public function getIndexTree($checkPermissions = true)
{
if (($forums = $this->cache->get('forums.index_tree')) == null) {
$forums = $this->decoratedRepository->getIndexTree(false);
$this->cache->forever('forums.index_tree', $forums);
}
if ($checkPermissions) {
$forums = $this->filterUnviewableForums($forums);
}
return $forums;
}
示例6: 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);
}
示例7: handle
/**
* Execute the console command.
*
* @param Repository $cache
*
* @return mixed
*/
public function handle(Repository $cache)
{
$iterations_count = $this->argument('iterations') ?: 1;
/** @var BaseBot $bot */
$bot = app('Bot');
while ($iterations_count--) {
$updatesChunk = $bot->getTelegram()->getUpdates($cache->get(self::CACHE_KEY) + 1, null, 3);
foreach ($updatesChunk as $update) {
$bot->handle($update);
$cache->forever(self::CACHE_KEY, $update->update_id);
}
}
}
示例8: refreshUsersStatus
/**
* Return the total users and logged users.
*
* @return array
*/
public function refreshUsersStatus()
{
$rtm = $this->slackRtm->start();
$totals = $this->getEmptyStatus();
foreach ($rtm['users'] as $user) {
if ($this->isRealUser($user)) {
$totals['total']++;
if ($this->isActiveUser($user)) {
$totals['active']++;
}
}
}
$this->cache->forever(self::SLACK_TOTALS_KEY, $totals);
return $totals;
}
示例9: syncRef
public function syncRef($ref, $type, Closure $progress = null)
{
$this->fire('git.syncer.start', [$ref, $type]);
$owner = $this->setting('owner');
$repo = $this->setting('repository');
$docPath = $this->setting('sync.paths.docs');
$menuPath = $this->setting('sync.paths.menu');
$indexPath = $this->setting('sync.paths.index');
$remote = $this->client($this->setting('remote'));
$rfs = $remote->getFilesystem($repo, $owner, $ref);
$files = $rfs->allFiles($this->setting('sync.paths.docs'));
if (!$rfs->exists($indexPath)) {
return $this->log('error', 'syncRef could not find the index file', [$indexPath]);
}
if (!$rfs->exists($menuPath)) {
return $this->log('error', 'syncRef could not find the menu file', [$indexPath]);
}
$destinationDir = $this->project->path($ref);
$menuContent = $rfs->get($this->setting('sync.paths.menu'));
//#base64_decode($menu[ 'content' ]);
$menuArray = Yaml::parse($menuContent);
$unfilteredPages = [];
$this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
$this->ensureDirectory($destinationDir);
$files = $rfs->allFiles($this->setting('sync.paths.docs'));
$total = count($files);
$syncer = $this;
foreach ($files as $current => $file) {
$localPath = Path::makeRelative($file, $this->setting('sync.paths.docs'));
if ($progress instanceof Closure) {
#$file = new \SplFileInfo(path_join($this->project->getPath(), $destinationDir, $localPath));
$this->project->getContainer()->call($progress, compact('current', 'total', 'file', 'files', 'syncer'));
}
$localPath = Path::join($destinationDir, $localPath);
$dir = Path::getDirectory($localPath);
$this->ensureDirectory($dir);
$this->files->put($localPath, $rfs->get($file));
}
// index.md resolving
$indexFile = $rfs->get($this->setting('sync.paths.index'));
$this->files->put(Path::join($destinationDir, 'index.md'), $indexFile);
if ($type === 'branch') {
$branch = $remote->getBranch($this->setting('repository'), $ref, $this->setting('owner'));
$this->cache->forever(md5($this->project->getName() . $branch['name']), $branch['sha']);
}
$this->fire('git.syncer.finish', [$ref, $type]);
}
示例10: save
/**
* {@inheritdoc}
*/
public function save(CacheItemInterface $item)
{
$expiresInMinutes = null;
if ($item instanceof CacheItem) {
$expiresInMinutes = $item->getTTL();
}
try {
if (is_null($expiresInMinutes)) {
$this->repository->forever($item->getKey(), serialize($item->get()));
} else {
$this->repository->put($item->getKey(), serialize($item->get()), $expiresInMinutes);
}
} catch (Exception $exception) {
return false;
}
return true;
}
示例11: syncRef
public function syncRef($ref, $type)
{
$this->project->getFactory()->log('info', 'codex.hooks.git.syncer.sync.start', compact('ref', 'type'));
$this->runHook('git:syncer:start', [$this, $ref, $type]);
$owner = $this->setting('owner');
$repo = $this->setting('repository');
$docPath = $this->setting('sync.paths.docs');
$indexPath = $this->setting('sync.paths.docs');
$remote = $this->client($this->setting('remote'));
$rfs = $remote->getFilesystem($repo, $owner, $ref);
$files = $rfs->allFiles($this->setting('sync.paths.docs'));
$indexExists = $rfs->exists(Path::join($this->setting('sync.paths.docs'), 'index.md'));
$menuExists = $rfs->exists(Path::join($this->setting('sync.paths.docs'), 'menu.yml'));
$a = 'b';
if (!$indexExists || !$menuExists) {
return;
}
$destinationDir = Path::join($this->project->getPath(), $ref);
$menuContent = $rfs->get($this->setting('sync.paths.menu'));
//#base64_decode($menu[ 'content' ]);
$menuArray = Yaml::parse($menuContent);
$unfilteredPages = [];
$this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
$this->ensureDirectory($destinationDir);
foreach ($rfs->allFiles($this->setting('sync.paths.docs')) as $path) {
$localPath = Path::makeRelative($path, $this->setting('sync.paths.docs'));
$localPath = Path::join($destinationDir, $localPath);
$dir = Path::getDirectory($localPath);
$this->ensureDirectory($dir);
$this->files->put($localPath, $rfs->get($path));
}
if ($type === 'branch') {
$branch = $remote->getBranch($this->setting('repository'), $ref, $this->setting('owner'));
$this->cache->forever(md5($this->project->getName() . $branch['name']), $branch['sha']);
}
$this->runHook('git:syncer:done', [$this, $ref, $type]);
$this->project->getFactory()->log('info', 'codex.hooks.git.syncer.sync.end', compact('ref', 'type'));
}
示例12: putCache
/**
* @param Role $role
* @param string $permission
* @param string|null $content
* @param int|null $contentID
* @param NEVER|NO|YES $value
*/
private function putCache(Role $role, $permission, $content, $contentID, $value)
{
$this->cache->forever("permission.{$role->role_slug}.{$permission}.{$content}.{$contentID}", $value);
}
示例13: cacheForever
/**
* Cache a value forever
* @param $key
* @param $value
*/
public function cacheForever($key, $value)
{
$this->cache->forever($this->cachePrefix($key), $value);
}
示例14: forever
/**
* Store an item in the cache indefinitely.
*
* @param string $key
* @param mixed $value
*/
public function forever($key, $value)
{
$this->cache->forever($key, $value);
}
示例15: syncRef
public function syncRef($ref, $type)
{
$content = new GitSyncContent($this->setting('owner'), $this->setting('repository'), $this->github);
$hasDocs = $content->exists($this->setting('sync.paths.docs'), $ref);
if (!$hasDocs) {
return;
}
$destinationDir = Path::join($this->project->getPath(), $ref);
$menu = $content->show($this->setting('sync.paths.menu'), $ref);
$menuContent = base64_decode($menu['content']);
$menuArray = Yaml::parse($menuContent);
$unfilteredPages = [];
$this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
$filteredPages = [];
# filter out pages that link to external sites
foreach ($unfilteredPages as $page) {
if (Str::startsWith($page, 'http', true) || Str::startsWith($page, '//', true) || Str::startsWith($page, 'git', true)) {
continue;
}
if (!in_array($page, $filteredPages, true)) {
$filteredPages[] = $page;
}
}
# get all pages their content and save to local
foreach ($filteredPages as $pagePath) {
$path = Path::join($this->setting('sync.paths.docs'), $pagePath . '.md');
# check if page exists on remote
$exists = $content->exists($path, $ref);
if (!$exists) {
continue;
}
# the raw github page content response
$pageRaw = $content->show('/' . $path, $ref);
# transform remote directory path to local directory path
$dir = Str::remove($pageRaw['path'], $this->setting('sync.paths.docs'));
$dir = Str::remove($dir, $pageRaw['name']);
$dir = Path::canonicalize(Path::join($destinationDir, $dir));
if (!$this->files->exists($dir)) {
$this->files->makeDirectory($dir);
}
# raw github page to utf8 and save it to local
$this->files->put(Path::join($dir, $pageRaw['name']), base64_decode($pageRaw['content']));
}
# save the menu to local
$this->files->put(Path::join($destinationDir, 'menu.yml'), $menuContent);
# if enabled, Get phpdoc structure and save it
if ($this->setting('phpdoc')) {
$hasStructure = $content->exists($this->setting('paths.phpdoc'), $ref);
if ($hasStructure) {
$structure = $content->show($this->setting('paths.phpdoc'), $ref);
$structureXml = base64_decode($structure['content']);
$destination = Path::join($destinationDir, 'structure.xml');
$destinationDir = Path::getDirectory($destination);
if (!$this->files->exists($destinationDir)) {
$this->files->makeDirectory($destinationDir);
}
$this->files->put($destination, $structureXml);
}
}
# set cache sha for branches, not for tags (obviously)
if ($type === 'branch') {
$branchData = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository'), $ref);
$this->cache->forever(md5($this->project->getName() . $branchData['name']), $branchData['commit']['sha']);
}
}