]> _ Git - cubist_cms-back.git/commitdiff
wip #5127
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 28 Feb 2022 16:01:34 +0000 (17:01 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 28 Feb 2022 16:01:34 +0000 (17:01 +0100)
src/app/Http/Controllers/CubistSelect2Controller.php
src/app/Magic/Fields/SelectFromArray.php

index 470fda1f3ecdd4ea57b231bba6103b84f29accc6..e3e11733acefbd09d57b68d762504a4121665a59 100644 (file)
@@ -6,6 +6,7 @@ use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Util\Text;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 
 class CubistSelect2Controller
 {
@@ -19,7 +20,7 @@ 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;
index 7b7deccbb7a6c0838918a3f76306f0297015b959..246e6a4e4c86a61db25534d9ecf431cb3123e602 100644 (file)
@@ -6,6 +6,7 @@ namespace Cubist\Backpack\Magic\Fields;
 
 use Cubist\Backpack\CubistBackpackServiceProvider;
 use Cubist\Util\Text;
+use Illuminate\Support\Facades\Cache;
 
 class SelectFromArray extends Field
 {
@@ -38,18 +39,15 @@ 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;
     }