anlutro / anlutro/laravel-settings
Custom setting store doesn't use cache (or incorrect instructions)
- Ngôn ngữ chính
- PHP
- Star
- 930
- Fork
- 113
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I had to extend the DatabaseSettingStore for some unimportant reasons. So I followed the instructions in the readme and added the a new class:
```php
class CustomDatabaseSettingStore extends Base
{
public function __construct(Connection $connection)
{
parent::__construct(
$connection,
config('settings.table'),
config('settings.keyColumn'),
config('settings.valueColumn')
);
}
// more code here
}
```
and I added the following to my AppServiceProvider:
```php
Setting::extend('customDatabaseSettingStore', function ($app) {
return $app->make(CustomDatabaseSettingStore::class);
});
```
I have caching enabled, but I found the setting cache suspiciously empty. So I checked, and it turns out that caching settings are never set in the custom store, and I think defaults also don't work. These are usually set in `SettingsManager::wrapDriver()` which is never called.
I had to add the code from `wrapDriver()` to my custom store:
```php
class CustomDatabaseSettingStore extends Base
{
public function __construct(Connection $connection)
{
parent::__construct(
$connection,
config('settings.table'),
config('settings.keyColumn'),
config('settings.valueColumn')
);
$this->setDefaults(config('settings.defaults'));
if (config('settings.enableCache')) {
$this->setCache(
app()['cache'],
config('settings.cacheTtl'),
config('settings.forgetCacheByWrite')
);
}
}
// more code
}
```
I think, at the very least, the readme should be updated. I was very surprised that this was needed, especially because it is usually handled by the SettingsManager, which I wouldn't have expected to have to look at. I would prefer if `wrapDriver()` was somehow called for custom drivers, but it would already be helpful if it were public and easily accessible.
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.