I think what you’re trying to do is done nowadays with URL parameters instead of sessions. What would happen if someone opened two tabs to your site and needed to go through them independently? The session for one would overwrite the other and they’d be confused and annoyed. If details are in the URL instead, then the tabs operate fully independently, as they (almost always) should.
Sorry, you said you wanted to “cache into a user session”. Sessions are inherently private to the user. I’m probably not understanding what you’re trying to do.
it will be saved individually only for the user that is logged in. But beside your problem with the article id’s you will also not be able to paginate through them if you do some thing like:
Okay, I think I understand what you’re trying to accomplish. Am I right in assuming that the $conditions are in some way user-specific and that’s why you need different caching per user?
I haven’t this sort of query caching, I’ve used Cache::remember instead to save (usually highly processed) results under keys that I specify. Can you just add the user ID into your cache key, like return ‘articles-’ . $user_id . '-' . md5(...?
Or some other form of caching? Or save the IDs to the user session and build your own pagination that uses that array with array_slice?
All of this is assuming that you have actual performance problems that this caching is going to resolve for you. Too many people build something like this just because it’s something that they thought might be a good idea to cut down on database queries even though the site isn’t really all that busy and can easily handle the load.
saves the “where” clause (conditions). But you can’t win anything here, if you save large amounts of those clauses … so you need the individual session caching…
will it be saved in the cache like here: $this->request->getSession()->read( ‘my_array’) but the position/name ‘my_array’ will be “articles-’ . $user->id . ‘-’ . md5(serialize($q->clause(‘where’)”
or will every article be its own variable and not an array?