I think I dreamt something was in the docs, but in reality it isn't. I'm using a taggable cache store, Redis. I thought that if you had cached a DB query with tags, you could use dot notation to access the tags later. Let's say I have two queries:
Thing::cacheTags('things.all')->remember(60)->get();
Thing::where('active',true)->cacheTags('things.active')->remember(60)->get();
Elsewhere in the code, say in an event handler, if I ran Cache::flush('things') I would expect that it would flush queries tagged things.all
and things.active
or things.*
. But apparently that ain't so, so now I have to do this:
Thing::cacheTags(['things','things.all'])->remember(60)->get();
Thing::where('active',true)->cacheTags(['things','things.all'])->remember(60)->get();
This works, but feels wrong to me. Am I doing it wrong? Is there a better way to create tagged subsets, but be able to flush the entire superset if needed?
My understanding is that your dot-notation assumption is incorrect and you must explicitly list the tags as you've done in your second example. Now, I say that "incorrect" in the sense that it doesn't work. I may not be thinking through all the potential drawbacks, but on the surface it seems like a pretty good convention to establish. I'd be curious to hear what others think.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community