use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Util\Text;
use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
class CubistSelect2Controller
{
}
$perPage = 10;
- $data = json_decode(file_get_contents(storage_path('select2/' . $hash . '.json')), true);
+ $data = Cache::get('select2_' . $hash);
$term = request()->get('q', null);
$page = request()->get('page', 1);
$offset = ($page - 1) * $perPage;
use Cubist\Backpack\CubistBackpackServiceProvider;
use Cubist\Util\Text;
+use Illuminate\Support\Facades\Cache;
class SelectFromArray extends Field
{
}
}
- public static function hashOptions($options){
+ public static function hashOptions($options)
+ {
$data = [];
foreach ($options as $k => $v) {
$data[$k] = ['t' => $v, 'n' => self::normalize($v)];
}
$hash = hash('sha256', print_r($data, true));
- $name = $hash . '.json';
- $dir = \Cubist\Util\Files\Files::mkdir(storage_path('select2'));
- $file = $dir . '/' . $name;
- if (!file_exists($file)) {
- file_put_contents($file, json_encode($data));
- }
+ Cache::add('select2_' . $hash, $data, 600);
+
return $hash;
}