public function pref($key, $value = null, $type = 'string')
    {
        if (isset($value)) {
            $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type),
                                                                   'type'  => $type, ]);

            Cache::put("{$this->slug}.'/'.{$key}", $value, 60);
            return $value;
        }

        if($value = Cache::get("{$this->slug}.'/'.{$key}"))
        {
            return $value;
        }

        if ($pref = $this->preferences()->forKey($key)->first()) {
            $value = $pref->value();
            $type = $pref->type();
        } else {
            $default = Preference::getDefault($this, $key);
            $value = $default->value();
            $type = $default->type();
        }
        
        Cache::put("{$this->slug}.'/'.{$key}", $value, 60);
        return $this->cast($value, $type);
    }