<p>Craft is using the default Yii <a href="https://www.yiiframework.com/doc/api/2.0/yii-db-connection#$queryCache-detail" rel="nofollow noreferrer">queryCache</a> component, which is set to the file system cache by default (i.e., what's in <code>storage/runtime/cache</code>.</p>

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

CC BY-SA 4.0
2019-08-08T18:24:32.017Z
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
CC BY-SA 4.0
2019-08-08T01:43:27.767Z
2019-08-08T01:43:27.767Z
Brad Bell
<p>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.</p>

<p>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.</p>

<relations><cache><elementquery>
How do I flush the query cache?
# How do I flush the query cache?

(Asked by: username_0 on 2019-08-07)

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.

**Tags:** relations, cache, elementquery


---

## 1 answers

### Answer by username_1 on 2019-08-08. Score: 0

Craft is using the default Yii [queryCache](https://www.yiiframework.com/doc/api/2.0/yii-db-connection#$queryCache-detail) 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()`.

> **Comments:**
> **username_0**: 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.  

---

