use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
use Cubist\Backpack\CubistBackpackServiceProvider;
+use DebugBar\DebugBar;
use Gaspertrix\Backpack\DropzoneField\Traits\HandleAjaxMedia;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App;
protected $_oneInstance;
protected $_nested = false;
- protected $hidden=[];
+ protected $hidden = [];
public function _postSetModel()
{
protected function _forgetCache()
{
- Cache::tags(Menu::CACHE_TAG)->flush();
+ $tags = [Menu::CACHE_TAG];
+ $model_instance = $this->getModelInstance();
+ $classes = array_merge([get_class($model_instance)], class_parents($model_instance));
+ foreach ($classes as $class) {
+ $tags[] = 'model_' . $class;
+ }
+
+ Cache::tags($tags)->flush();
}
public function index()
protected function _getOptions()
{
- $cacheKey = $this->getAttribute('optionsmodel');
+ $modelClass = $this->getAttribute('optionsmodel');
+ $attr = $this->getAttribute('attribute');
+ $cacheKey = '_getOption_Model_' . $modelClass . '-' . $attr;
- if (!isset(static::$_options[$cacheKey])) {
- static::$_options[$cacheKey] = $this->__getOptions();
+ if (isset(static::$_options[$cacheKey])) {
+ return static::$_options[$cacheKey];
}
- return static::$_options[$cacheKey];
- }
- protected function __getOptions()
- {
- $modelClass = $this->getAttribute('optionsmodel');
- /** @var \Illuminate\Database\Eloquent\Model $inst */
- $inst = new $modelClass();
+ start_measure($cacheKey, 'Get options for model ' . $modelClass . ' / ' . $attr);
+ $tag='model_' . $modelClass;
+ static::$_options[$cacheKey] = cache()->tags([$tag])->remember($cacheKey, 86400, function () use ($modelClass, $attr) {
+ /** @var \Illuminate\Database\Eloquent\Model $inst */
+ $inst = new $modelClass();
+ $options = $modelClass::all();
- $attr = $this->getAttribute('attribute');
- $options = $modelClass::all();
+ return $options->pluck($attr, $inst->getKeyName())->toArray();
+ });
+ stop_measure($cacheKey);
- return $options->pluck($attr, $inst->getKeyName())->toArray();
+ return static::$_options[$cacheKey];
}
public function getDatabaseType()
}
if (!isset(self::$_nav[$variant][$locale])) {
- \Barryvdh\Debugbar\Facade::startMeasure('nav', 'Init Navigation object');
+ start_measure('nav', 'Init Navigation object');
self::$_nav[$variant][$locale] = Cache::tags(self::CACHE_TAG)->remember('navigation_' . $variant . '_' . $locale, 43200, function () use ($locale, $variant) {
$nav = new Item();
$nav->setLocale($locale);
$nav->initFromDatabase();
return $nav;
});
- \Barryvdh\Debugbar\Facade::stopMeasure('nav');
+ stop_measure('nav');
}
return self::$_nav[$variant][$locale];