dongmu6225 2013-01-08 22:50
浏览 63
已采纳

我应该在数据库或cookie中存储非敏感信息以减少加载时间吗?

I am programming a page primarily in PHP and I was wondering if it would be better to grab a bunch of the non-sensitive info about a user from the database and put it into cookies for faster loading on future pages, or if I should have each page access the database several times?

The pages don't load particularly slowly, but there is a slight, noticeable delay for the sql query and PHP to populate the page. It could just be my server, but I would like to make sure my code is efficient before I worry about that.

  • 写回答

3条回答 默认 最新

  • dongyou6768 2013-01-08 22:52
    关注

    Putting data in cookies means the user can alter it (which doesn't seem to be a problem for you), or that the user can erase it, perhaps by accident, requiring the data to somehow be filled again.

    Why not put it in the session? It's managed on the server side, cached properly by any decent server, and you can reload data from the database if you create a new session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部