Jiang qinghua 6 years ago
parent
commit
36508a1569
2 changed files with 15 additions and 5 deletions
  1. 4 2
      src/Models/Menu.php
  2. 11 3
      src/Models/MenuCache.php

+ 4 - 2
src/Models/Menu.php

@@ -69,11 +69,13 @@ class Menu extends Model
     }
 
     /**
+     * @param bool $force
+     *
      * @return array
      */
-    public function allNodes() : array
+    public function allNodes(bool $force = false): array
     {
-        if ($this->queryCallback instanceof \Closure) {
+        if ($force || $this->queryCallback instanceof \Closure) {
             return $this->fetchAll();
         }
 

+ 11 - 3
src/Models/MenuCache.php

@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Cache;
 
 trait MenuCache
 {
-    protected $cacheKey = 'dcat-admin-menus';
+    protected $cacheKey = 'dcat-admin-menus-%d';
 
     /**
      * Get an item from the cache, or execute the given Closure and store the result.
@@ -20,7 +20,7 @@ trait MenuCache
             return $builder();
         }
 
-        return $this->getStore()->remember($this->cacheKey, null, $builder);
+        return $this->getStore()->remember($this->getCacheKey(), null, $builder);
     }
 
     /**
@@ -34,7 +34,15 @@ trait MenuCache
             return null;
         }
 
-        return $this->getStore()->delete($this->cacheKey);
+        return $this->getStore()->delete($this->getCacheKey());
+    }
+
+    /**
+     * @return string
+     */
+    protected function getCacheKey()
+    {
+        return sprintf($this->cacheKey, (int)static::withPermission());
     }
 
     /**