sumac_leaves's avatar

How do I search for all cached items where the key starts with a string? Or what is a replacement for Cache tags?

I want to track user activity with this controller:

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $user = auth('api')->id();

        if ($user) {
           Cache::put('last_active.' . $user, now());
        }
    }
}

Then on a schedule running every 10 minutes, find all Cache items matching last_active.*, then update the User's last_active column.

I initially reached for Cache tags, but they are no longer documented or recommended. What should I do instead?

0 likes
1 reply
Snapey's avatar

Put the items inside an array. You can load it as one entity, add or remove from it and write it back to cache?

Please or to participate in this conversation.