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.

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?