]> _ Git - cubist_cms-back.git/commitdiff
wip #4210 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Jun 2022 07:51:24 +0000 (09:51 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Jun 2022 07:51:24 +0000 (09:51 +0200)
src/app/Cache.php [new file with mode: 0644]
src/app/Console/Commands/PrecacheCommand.php

diff --git a/src/app/Cache.php b/src/app/Cache.php
new file mode 100644 (file)
index 0000000..a8b401d
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace Cubist\Backpack;
+
+class Cache extends \Illuminate\Support\Facades\Cache
+{
+    public function rememberOrRefresh(string $key, \DateTimeInterface|\DateInterval|int $ttl, \Closure $callback, $refresh = false)
+    {
+        if ($refresh) {
+            $data = $callback();
+            self::put($key, $data, $ttl);
+            return $data;
+        } else {
+            return self::remember($key, $ttl, $callback);
+        }
+    }
+}
index 0a3e5a0ffff3a2aa59eb9639b3625793cfb179ef..967539efcdc1ad1dd592f3a4c9732018efde852b 100644 (file)
@@ -15,14 +15,23 @@ class PrecacheCommand extends CubistMagicCommand
 
     public function handle()
     {
+        $this->_handleMagicFolder([$this, '_precacheForce']);
         $this->_handleMagicFolder([$this, '_precache']);
     }
 
     /**
      * @param $model CubistMagicAbstractModel
      */
-    public function _precache($model)
+    public function _precacheForce($model)
     {
         $model->preCache(true);
     }
+
+    /**
+     * @param $model CubistMagicAbstractModel
+     */
+    public function _precache($model)
+    {
+        $model->preCache(false);
+    }
 }