Open titleistfour opened 10 years ago
I was wondering the same. Caching the permission calls would certainly help reduce queries that arent needed all the time.
+1
Good idea. I'm gonna do this
Hey @Zizaco! What is the status on this?
+1 Would be glad if the queries were optimised/cached. My app makes quite a few ajax calls and I can see Entrust firing quite a lot of similar queries for each of them. Considering roles don't change all that often, caching them would be ideal. May be those caches can be invalidated when new roles are added/updated.
+1 I'm looking for the cache too. Is there any similar solution available now? This would be quite useful. Thanks
@censhen I'm working on a package. I am currently using it in several of my own projects as I don't know the exact functional pitfalls yet. You can add me on Skype if you're interested in testing or contributing; rasmusdencker
@dondencker Thanks for your info. Your package sounds interesting. But currently I'm working on another project. I may contact you after that project.
The best thing you can do is eager loading the roles attribute, and overwriting the hasRole() method :
protected $with = ['roles'];
..
use HasRole {
hasRole as traitHasRole;
}
..
public function hasRole($name) {
$roles = $this->roles;
if (!$roles) {
$roles = $this->roles()->get();
}
..
The structure of the queries in Traits right now are not conducive to caching. They're currently using Lazy Loading. Eager Loading is much easier to cache. Optimizing these would require a decent bit of restructuring.
I'm going to take a stab at it, but don't hold your breath.
Please do!
On Thu, Nov 19, 2015 at 1:34 PM Scott Connerly notifications@github.com wrote:
The structure of the queries in Traits right now are not conducive to caching. They're currently using Lazy Loading. Eager Loading is much easier to cache. Optimizing these would require a decent bit of restructuring.
I'm going to take a stab at it, but don't hold your breath.
— Reply to this email directly or view it on GitHub https://github.com/Zizaco/entrust/issues/107#issuecomment-158204726.
Hi All !
This evolution is it being developed?
Thank's a lot this is a good plugin. With cache, it's will be perfect !
What is situation here?
+1
+1
+1
+1
+1
+1
+1
Actually guys, its already been implemented. You can use it by adding key to config/cache.php, add folowing:
'ttl' => 30 //In minutes
Please note that, you'll need cache driver that support tagging like redis or i believe memcahe as well.
I don't know if it's official yet, but i'm using it and it works pretty well IMO. Cut down my site loading from 1s to 500ms on Windows.
Hi, is it possible that the caching doesn't refresh when a new role/permission is attached to/removed from a user/role?
I'm using $user->attachRole($role);
but it takes 'cache.ttl'
minutes to show up in the GUI.
@PKeidel , i think so. I have a similar issue with $role->perms()->toggle($perms);
I tried to fix it by using :
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
But it doesn't work. Any workaround or similar issues ?
I have 'ttl' => 30 //In minutes in config/cache.php and caching works perfectly.
However when new user is created, in my own case via registration form and a certain role is assigned automatically, role doesn't take effect until I manually run php artisan cache:clear
How do I refresh cached user roles
Hi,
On sites with a large number of permissions and roles, and pages where you need to check those to display content, it seems that this incurs quite a few database calls.
Does Entrust have any support for caching to reduce the calls back to the database?
Thanks, Jay