且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在CodeIgniter中设置全局变量的***方法?

更新时间:2023-11-12 18:58:34

将数据存储在数据库中?如果您担心效果,可以使用 Memcache APC 来缓存它,但似乎注释计数和点是需要在会话之间持久的数据。



您仍然需要将数据写入数据库以及缓存,但是您可以直接从缓存读取数据,而不是查询。 / p>

I'm using CodeIgniter and I have user data that needs to be stored in some way then updated. Basic things like name, id, points, comment count etc

At the moment when the user logs in I simply get their data and store it in a session. Now obviously the name and id would never change, but the Points and Comment count etc will change from page to page depending on the user actions.

As this data will be constantly changing, what would be the best way to store it , update it and make it available throughout my app? I'm not sure if updating the session every time the user performs an action is the best way though?

I thought about maybe using a CodeIgniter hook to run a function that sets up a variable ready for use?

Whats the best way? Any ideas?

Thanks, Sean Jenkins

Why can't you store the data in a database? If your worried about performance you could use something like Memcache or APC to cache it but it seems like comment count and points are data that need to persist between sessions.

You would still need to write the data to the database as well as the cache but then you could read the data directly from the cache instead of querying for it.