Rewrite all implementations of remember() on models

This commit is contained in:
Samuel Georges 2015-02-04 19:52:59 +11:00
parent beb818efa5
commit 899100919d
3 changed files with 17 additions and 11 deletions

View File

@ -1,5 +1,6 @@
<?php namespace Backend\Behaviors;
use Cache;
use System\Behaviors\SettingsModel;
use Backend\Models\UserPreferences;
@ -62,9 +63,13 @@ class UserPreferencesModel extends SettingsModel
public function getSettingsRecord()
{
$item = UserPreferences::forUser();
$record = $item->scopeFindRecord($this->model, $this->recordCode, $item->userContext)
->remember(1440, $this->getCacheKey())
->first();
$record = Cache::remember($this->getCacheKey(), 1440, function() use ($item) {
return $item->scopeFindRecord(
$this->model,
$this->recordCode,
$item->userContext
)->first();
});
return $record ?: null;
}

View File

@ -129,10 +129,9 @@ class Theme
$activeTheme = Config::get('cms.activeTheme');
if (DbDongle::hasDatabase()) {
$dbResult = Parameters::findRecord(self::ACTIVE_KEY)
->remember(1440, self::ACTIVE_KEY)
->pluck('value')
;
$dbResult = Cache::remember(self::ACTIVE_KEY, 1440, function() {
return Parameters::findRecord(self::ACTIVE_KEY)->pluck('value');
});
if ($dbResult !== null && static::exists($dbResult)) {
$activeTheme = $dbResult;

View File

@ -110,10 +110,12 @@ class SettingsModel extends ModelBehavior
*/
public function getSettingsRecord()
{
$record = $this->model
->where('item', $this->recordCode)
->remember(1440, $this->getCacheKey())
->first();
$record = Cache::remember($this->getCacheKey(), 1440, function() {
return $this->model
->where('item', $this->recordCode)
->first();
});
return $record ?: null;
}