I'm building a REST API with Lumen and want to cache some of the routes with Redis. E.g. for the route /users/123/items I use:
$items = Cache::remember('users:123:items', 60, function () {
// Get data from database and return
});
When a change is made to the user's items, I clear the cache with:
Cache::forget('users:123:items');
So far so good. However, I also need to clear the cache I've implemented for the routes /users/123 and /users/123/categories since those include an item list as well. This means I also have to run:
Cache::forget('users:123');
Cache::forget('users:123:categories');
In the future, there might be even more caches to clear, which is is why I'm looking for a pattern/wildcard feature such as:
Cache::forget('users:123*');
Is there any way to accommodate this behavior in Lumen/Laravel?