avoiding DB session update overhead

I am using Yii2 with DB level session. Also implemented Roles Privileges model where in it is storing required privileges to user/role

when user hits the page it is taking these allowed privileges array into session i.e in session table.

and then after it is loading it from there for that page.

but while storing it for each request it takes time as its DB update. is there any alternative for same where in i will reduce query update overhead.

You have many options…

http://www.yiiframework.com/doc-2.0/guide-runtime-sessions-cookies.html

Cache would probably be the fastest.

-John Scot

Normally yii2 RBAC as far as I know works as follow

at login user permission are retrieved and stored in cache (either file, redis or whatever you configured as cache)

So next time you check permission the RBAC check them against the cache rather then query again.

If you update permission (creating new one, adding/deleting permission to users) the cache is flushed so user get changes immediately

Therefore you do not need to store them in session.