dt888999 2014-01-29 19:12
浏览 31
已采纳

从symfony 2访问所有存储的会话?

I am currently storing an array in the users session that is pulled out of the database and rarely if at all changes during a users session. This way i dont have to re-query for the data everytime a new page is loaded. However, i would like to have a way so that if the data changes that part of the users session is unset. This would force the application to query for the new data and then store it in the session again.

Lets say im storing the number of blog posts that user has access too in their sessions. When a new blog post is created that the user will have access too i want to have an event listener fire and unset the part of all currently active sessions that store this. I would then either wait until the user loaded another page and refresh this then or someway, "warm up" this cache.

This is probably a bad example as it may be updated more frequently and may have better ways of doing it but it is just and example.

If you could provide a way to access all the sessions and modify just the part storing this data that would be perfect.

EDIT: Updated the example to more closely resemble the problem. Im trying to do user specific so simple key => value pairs may not work because the key would need to be a user/unique key identifier and the value would be all the blog posts they have access too.

  • 写回答

1条回答 默认 最新

  • douwan2664 2014-01-30 06:28
    关注

    Don't use the users session as a cache. It will give you a headache and will make things complicated.

    If you only want to cache user independent data for performance reasons, you should consider using memcached as an in-memory key=>value storage cache. You will hardly find anything that is faster.

    If you don't want to install memcached, but already have APC installed, you could also use the APC data store cache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部