| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\common\modules\site;
- class SiteSetting
- {
- private $setting;
- private $expiredTimestamp;
- public function loadSettingFromCache()
- {
- $this->setting = \app\common\facades\SiteSettingCache::get();
- $this->expiredTimestamp = time() + 20;
- }
- public function getSetting()
- {
- if (!isset($this->setting)) {
- $this->loadSettingFromCache();
- }
- if (time() > $this->expiredTimestamp) {
- $this->loadSettingFromCache();
- }
- return $this->setting;
- }
- /**
- * @param $key
- * @return bool
- */
- public function has($key)
- {
- return array_has($this->getSetting(), $key);
- }
- /**
- * @param $key
- * @param null $default
- * @return mixed
- */
- public function get($key, $default = null)
- {
- return array_get($this->getSetting(), $key, $default);
- }
- /**
- * @param $key
- * @param $value
- * @param null $minutes
- * @return mixed
- */
- public function set($key, $value)
- {
- \app\common\facades\SiteSettingCache::put($key, $value);
- }
- }
|