Reputation: 9362
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.
Upvotes: 2
Views: 380
Reputation: 884
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.
Upvotes: 3