Replies: 20 comments 5 replies
-
This package always caches the queries for which it is written to do caching (there are some which it doesn't because those wouldn't make sense). There's no turning the cache off or bypassing it ... unless your local environment is configured to use a memory-only cache such as |
Beta Was this translation helpful? Give feedback.
-
I believe caching works by default, but I don't see anything in cache. I understand that with the default settings, the below code in
But if I replace the This is on latest Laravel 8 (8.24). I used the |
Beta Was this translation helpful? Give feedback.
-
Using
It seems to be solved as the cache is filled. The only three queries that get run every page load for me (after the cache is warm) are: And then: I think this is all expected behavior. @damchey have you updated/can you update? If so, can you confirm it's now working for you? |
Beta Was this translation helpful? Give feedback.
-
Upgraded to 4.0.1 , am still getting 5 queries for every page load.
|
Beta Was this translation helpful? Give feedback.
-
any update? |
Beta Was this translation helpful? Give feedback.
-
Many have raised this issue, still can't find a solution for this! |
Beta Was this translation helpful? Give feedback.
-
Same issues here. In the docs it says there is no need to do any extra steps to enable caching as it is enabled by default. By I don't see any caching in action and I see lots of queries made to DB for the permission/role stuff |
Beta Was this translation helpful? Give feedback.
-
@freekmurze any comment regarding this issue? |
Beta Was this translation helpful? Give feedback.
-
Same issue on my application, using the middleware roles. Too many queries in the DB, so application to be slow. Please fixing this issue! |
Beta Was this translation helpful? Give feedback.
-
@drbyte any update?### |
Beta Was this translation helpful? Give feedback.
-
Same issue on my application when listing users. This is a big performance issue. |
Beta Was this translation helpful? Give feedback.
-
Hi guys, @damchey, @anwardote, @a-ssassi-n, @xperator, @arislanhaikal, @yeaggercom cache won't get created - If you create Permissions or Roles also cache won't get created when you assign permissions or role to user but cache will get created when you actually read For example:
the package works exactly as it should be 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
Have you check the queries with Laravel Debug Bar or any other SQL query viewing tools? |
Beta Was this translation helpful? Give feedback.
-
Hi @a-ssassi-n, Yea, I have said that after checking it with |
Beta Was this translation helpful? Give feedback.
-
When I tried to reload any page then always run 5 query. Does it ok? Have there any way to decrease number of queries? |
Beta Was this translation helpful? Give feedback.
-
@ajuchacko91 I don't think we're supposed to directly read from cache. Are we? We're calling functions and methods provided by this library, and I believe it should be implemented inside each one of these functions to try to read from cache whenever possible. |
Beta Was this translation helpful? Give feedback.
-
@xperator yea correct When you try to check permission first time on a request package creates the cache and uses it on subsequent calls. For example:
bye |
Beta Was this translation helpful? Give feedback.
-
Yes, cache works. This cache only saves the permissions to roles map (default cache key "spatie.permission.cache") My question is should we enable per user cache? It could be nice config option to allow caching user permissions. As for the many queries switching Spatie\Permission\Models\Role and Spatie\Permission\Models\Permission from $guarded to $fillable will reduce 2 excess queries on each page load.
Additionally if there is user cache all queries will be eliminated which may be good use case for some. |
Beta Was this translation helpful? Give feedback.
-
I think I have same question here |
Beta Was this translation helpful? Give feedback.
-
Hi to everybody, I dont know if my solution is good, but what I'm doing is copy the middleware \Spatie\Permission\Middlewares\PermissionMiddleware::class and change the code to get the user's permissions from cache... then I chankge the link in kernel.php to use my own middleware, in my case I only use permissions from middleware routes... sorry for my english. |
Beta Was this translation helpful? Give feedback.
-
Have installed version 3.18 with Laravel 8 and can't seem to get the cache working. Through debugbar I can see that every page makes several queries related to this permissions/roles.
Have used file, redis and database drivers. Haven't changed anything in the config/permission.php file. Using the provided API/methods to create/edit/sync roles & permissions, so not doing it directly through the database.
When I test for cache using
Cache::get('spatie.permission.cache')
, it returns null.Can confirm that my cache/driver is working by doing
Cache::put('test_name', 'test_value')
I can get thetest_value
.Beta Was this translation helpful? Give feedback.
All reactions