Skip to content

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

Open
@bjhijmans

Description

@bjhijmans

I had to extend the DatabaseSettingStore for some unimportant reasons. So I followed the instructions in the readme and added the a new class:

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:

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions