Showing
3 changed files
with
14 additions
and
6 deletions
| 1 | <?php namespace BookStack\Providers; | 1 | <?php namespace BookStack\Providers; |
| 2 | 2 | ||
| 3 | +use BookStack\Services\SettingService; | ||
| 4 | +use BookStack\Setting; | ||
| 3 | use Illuminate\Support\ServiceProvider; | 5 | use Illuminate\Support\ServiceProvider; |
| 4 | use Validator; | 6 | use Validator; |
| 5 | 7 | ||
| ... | @@ -30,6 +32,8 @@ class AppServiceProvider extends ServiceProvider | ... | @@ -30,6 +32,8 @@ class AppServiceProvider extends ServiceProvider |
| 30 | */ | 32 | */ |
| 31 | public function register() | 33 | public function register() |
| 32 | { | 34 | { |
| 33 | - // | 35 | + $this->app->singleton(SettingService::class, function($app) { |
| 36 | + return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository')); | ||
| 37 | + }); | ||
| 34 | } | 38 | } |
| 35 | } | 39 | } | ... | ... |
| ... | @@ -16,6 +16,7 @@ class SettingService | ... | @@ -16,6 +16,7 @@ class SettingService |
| 16 | 16 | ||
| 17 | protected $setting; | 17 | protected $setting; |
| 18 | protected $cache; | 18 | protected $cache; |
| 19 | + protected $localCache = []; | ||
| 19 | 20 | ||
| 20 | protected $cachePrefix = 'setting-'; | 21 | protected $cachePrefix = 'setting-'; |
| 21 | 22 | ||
| ... | @@ -40,8 +41,12 @@ class SettingService | ... | @@ -40,8 +41,12 @@ class SettingService |
| 40 | public function get($key, $default = false) | 41 | public function get($key, $default = false) |
| 41 | { | 42 | { |
| 42 | if ($default === false) $default = config('setting-defaults.' . $key, false); | 43 | if ($default === false) $default = config('setting-defaults.' . $key, false); |
| 44 | + if (isset($this->localCache[$key])) return $this->localCache[$key]; | ||
| 45 | + | ||
| 43 | $value = $this->getValueFromStore($key, $default); | 46 | $value = $this->getValueFromStore($key, $default); |
| 44 | - return $this->formatValue($value, $default); | 47 | + $formatted = $this->formatValue($value, $default); |
| 48 | + $this->localCache[$key] = $formatted; | ||
| 49 | + return $formatted; | ||
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | /** | 52 | /** |
| ... | @@ -71,9 +76,8 @@ class SettingService | ... | @@ -71,9 +76,8 @@ class SettingService |
| 71 | 76 | ||
| 72 | // Check the cache | 77 | // Check the cache |
| 73 | $cacheKey = $this->cachePrefix . $key; | 78 | $cacheKey = $this->cachePrefix . $key; |
| 74 | - if ($this->cache->has($cacheKey)) { | 79 | + $cacheVal = $this->cache->get($cacheKey, null); |
| 75 | - return $this->cache->get($cacheKey); | 80 | + if ($cacheVal !== null) return $cacheVal; |
| 76 | - } | ||
| 77 | 81 | ||
| 78 | // Check the database | 82 | // Check the database |
| 79 | $settingObject = $this->getSettingObjectByKey($key); | 83 | $settingObject = $this->getSettingObjectByKey($key); | ... | ... |
| ... | @@ -64,7 +64,7 @@ function userCan($permission, Ownable $ownable = null) | ... | @@ -64,7 +64,7 @@ function userCan($permission, Ownable $ownable = null) |
| 64 | */ | 64 | */ |
| 65 | function setting($key = null, $default = false) | 65 | function setting($key = null, $default = false) |
| 66 | { | 66 | { |
| 67 | - $settingService = app(\BookStack\Services\SettingService::class); | 67 | + $settingService = resolve(\BookStack\Services\SettingService::class); |
| 68 | if (is_null($key)) return $settingService; | 68 | if (is_null($key)) return $settingService; |
| 69 | return $settingService->get($key, $default); | 69 | return $settingService->get($key, $default); |
| 70 | } | 70 | } | ... | ... |
-
Please register or sign in to post a comment