public function settings($key = null)
    {
        $plugin = $this->name();
        if ($cache = $this->config('settings')) {
            if ($key !== null) {
                $cache = isset($cache[$key]) ? $cache[$key] : null;
            }

            return $cache;
        }

        $pluginsTable = TableRegistry::get('System.Plugins');
        $settings = [];
        $dbInfo = $pluginsTable->find()
            ->cache("{$plugin}_settings", 'plugins')
            ->select(['name', 'settings'])
            ->where(['name' => $plugin])
            ->limit(1)
            ->first();

        if ($dbInfo) {
            $settings = (array)$dbInfo->settings;
        }

        if (empty($settings)) {
            $settings = (array)$pluginsTable->trigger("Plugin.{$plugin}.settingsDefaults")->result;
        }

        $this->config('settings', $settings);
        if ($key !== null) {
            $settings = isset($settings[$key]) ? $settings[$key] : null;
        }

        return $settings;
    }