dt888999 2014-01-30 03: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 14: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.

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

报告相同问题?

悬赏问题

  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)