$tag = 'model_' . $modelClass;
if ($force || !isset(static::$_options[$globalCacheKey])) {
- if ($force) {
- cache()->forget($globalCacheKey);
- }
start_measure($globalCacheKey, 'Get options for model ' . $modelClass . ' / ' . $attr);
- static::$_options[$globalCacheKey] = cache()->tags([$tag])->remember($globalCacheKey, 86400, function () use ($modelClass, $attr, $modelScope) {
+ $closure = function () use ($modelClass, $attr, $modelScope) {
set_time_limit(0);
/** @var \Illuminate\Database\Eloquent\Model $inst */
$inst = new $modelClass();
$q = $q->$modelScope();
}
return $q->where('created_ok', 1)->get()->pluck($attr, $inst->getKeyName())->toArray();
- });
+ };
+ $ttl = 86400;
+ $cache = cache()->tags([$tag]);
+ if ($force) {
+ static::$_options[$globalCacheKey] = $closure();
+ $cache->put($globalCacheKey, $ttl, static::$_options[$globalCacheKey]);
+ } else {
+ static::$_options[$globalCacheKey] = $cache->remember($globalCacheKey, $ttl, $closure);
+ }
stop_measure($globalCacheKey);
}
return static::$_options[$cacheKey];
}
- if ($force || !isset(static::$_options[$cacheKeysKey])) {
- if ($force ) {
- cache()->forget($cacheKeysKey);
- }
+ if (!isset(static::$_options[$cacheKeysKey])) {
static::$_options[$cacheKeysKey] = cache()->tags([$tag])->remember($cacheKeysKey, 86400, function () use ($modelClass, $modelOrderBy, $modelOrderByWay) {
set_time_limit(0);
/** @var Builder $q */
});
}
- if ($force) {
- cache()->forget($cacheKey);
- }
static::$_options[$cacheKey] = cache()->tags([$tag])->remember($cacheKey, 86400, function () use ($globalCacheKey, $cacheKeysKey) {
$res = [];
foreach (static::$_options[$cacheKeysKey] as $k) {