SiteSetting.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\common\modules\site;
  3. class SiteSetting
  4. {
  5. private $setting;
  6. private $expiredTimestamp;
  7. public function loadSettingFromCache()
  8. {
  9. $this->setting = \app\common\facades\SiteSettingCache::get();
  10. $this->expiredTimestamp = time() + 20;
  11. }
  12. public function getSetting()
  13. {
  14. if (!isset($this->setting)) {
  15. $this->loadSettingFromCache();
  16. }
  17. if (time() > $this->expiredTimestamp) {
  18. $this->loadSettingFromCache();
  19. }
  20. return $this->setting;
  21. }
  22. /**
  23. * @param $key
  24. * @return bool
  25. */
  26. public function has($key)
  27. {
  28. return array_has($this->getSetting(), $key);
  29. }
  30. /**
  31. * @param $key
  32. * @param null $default
  33. * @return mixed
  34. */
  35. public function get($key, $default = null)
  36. {
  37. return array_get($this->getSetting(), $key, $default);
  38. }
  39. /**
  40. * @param $key
  41. * @param $value
  42. * @param null $minutes
  43. * @return mixed
  44. */
  45. public function set($key, $value)
  46. {
  47. \app\common\facades\SiteSettingCache::put($key, $value);
  48. }
  49. }