anlutro / anlutro/laravel-settings

Custom setting store doesn't use cache (or incorrect instructions)

Đang mở
#168 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
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

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.