查询以前缓存的资源

I'm using Laravel 5.1 and memcached, and I'm attempting to find a way to query some data that's previously been cached.

For example, say I have a bunch of events from emails cached, such as clicks, opens, etc.

I'll cache all the events for one particular user like so:

$events = \Cache::section(Events::table())->remember('events-' . Session::get('uid'), 30, function() {
   return Events::select()
      ->where('user_id', Session::get('uid'))
      ->get();
});

Now I want to be able to query $events when the user is viewing particular emails, so it would be something like this:

$events->where('email_id', $id)->get();

I've been unable to find a way to properly do this, and I'm not quite sure what to even search for. Everything I've tried has failed so far.

I would imagine it's possible, I just don't know how to go about it.

Cache will return the collection of events. So $event has the collection of items.

To get the data you need to use all() method of collection like so:

$events->where('email_id', $id)->all();

If you don't provide any key to get() it will return null. Check here: https://laravel.com/docs/5.4/collections#method-get

For more check the available methods of Collection : https://laravel.com/docs/5.4/collections#method-contains