mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Merge branch 'develop' into wip/table-min-max-items
This commit is contained in:
commit
c9850db94a
@ -16,6 +16,10 @@ use System\Classes\ModelBehavior;
|
||||
* public $settingsCode = 'author_plugin_code';
|
||||
* public $settingsFields = 'fields.yaml';
|
||||
*
|
||||
* Optionally:
|
||||
*
|
||||
* public $settingsCacheTtl = 1440;
|
||||
*
|
||||
*/
|
||||
class SettingsModel extends ModelBehavior
|
||||
{
|
||||
@ -25,6 +29,11 @@ class SettingsModel extends ModelBehavior
|
||||
protected $fieldConfig;
|
||||
protected $fieldValues = [];
|
||||
|
||||
/**
|
||||
* @var integer Settings cache TTL, in seconds.
|
||||
*/
|
||||
protected int $cacheTtl = 1440;
|
||||
|
||||
/**
|
||||
* @var array Internal cache of model objects.
|
||||
*/
|
||||
@ -62,6 +71,10 @@ class SettingsModel extends ModelBehavior
|
||||
* Parse the config
|
||||
*/
|
||||
$this->recordCode = $this->model->settingsCode;
|
||||
|
||||
if ($this->model->propertyExists('settingsCacheTtl')) {
|
||||
$this->cacheTtl = (int) $this->model->settingsCacheTtl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,10 +121,13 @@ class SettingsModel extends ModelBehavior
|
||||
*/
|
||||
public function getSettingsRecord()
|
||||
{
|
||||
$record = $this->model
|
||||
->where('item', $this->recordCode)
|
||||
->remember(1440, $this->getCacheKey())
|
||||
->first();
|
||||
$query = $this->model->where('item', $this->recordCode);
|
||||
|
||||
if ($this->cacheTtl > 0) {
|
||||
$query = $query->remember($this->cacheTtl, $this->getCacheKey());
|
||||
}
|
||||
|
||||
$record = $query->first();
|
||||
|
||||
return $record ?: null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user