I am using Yii2 and using the yiirbacDbManager
for auth assignment.
I was looking at the logs to see where all the database calls are coming from and this query
SELECT `b`.* FROM `auth_assignment` `a`, `auth_item` `b` WHERE
((`a`.`item_name`=`b`.`name`) AND (`a`.`user_id`='91')) AND (`b`.`type`=1)
Keeps running again and again, sometimes 10/15 times in succession.
I have added
'authManager' => [
'class' => 'yiirbacDbManager',
'cache' => 'cache'
],
As the docs say that will cache the auth assignments (I am using Memcached). But it doesnt seem to work…
Anyone have any idea? Either how to cache it or why it keeps getting called so many times?
Cheers
2
Answers
https://github.com/yiisoft/yii2/issues/3168
Only cache
auth_item
,auth_rule
andauth_item_child
data. All thesedata are cached as a single entry in cache. Note that
auth_assignment
is too big to be cached (imagine a system withmillions of users).
Add caching in
vendor/yiisoft/yii2/rbac/DbManager.php
(Also in all places you need caching)
this code: