How do I flush Craft's query cache so that I may query a relationship field again in the same web request with a new set of parameters? In this particular scenario, I need to handle it inside of a custom module so I need PHP and not Twig.

Yes, I am fully aware of cloning the original query in order to make a second query with modified parameters so do not mention that in your answer. It is not an option in this scenario and it does not answer my question.


Craft is using the default Yii queryCache component, which is set to the file system cache by default (i.e., what's in storage/runtime/cache.

There's no way to clear specific items in that cache, but you can clear all of it with Craft::$app->getCache()->flush().

| improve this answer | |
  • Is there a way that I can instead perform a query and have it overlook the cache? I tried doing something like $entry->categoryField->noCache()->orderBy('level', 'desc')->one() but it still seems to pull the results from the cache and they are ordered by level, ascending. – Benjamin Kohl Aug 8 '19 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.