# Removing queries from cache

You can manually remove a cached query from cache before its natural TTL-driven expiration time by using the [DatabaseProvider::clearCacheQuery](/version-0.x/reference/core-classes/databaseprovider/databaseprovider-methods.md#clearcachequery) method, here's an example:

```php
$e->Database->main->clearCacheQuery([
    "uniqueId" => "usersSignedUpLast24Hours"
]);
```

Because query cache keys are automatically generated if you don't specify any [Cache key naming](/version-0.x/guide/database-guide/cache-key-naming.md) when calling methods like [DatabaseProvider::queryCache](/version-0.x/reference/core-classes/databaseprovider/databaseprovider-methods.md#querycache) and [DatabaseProvider::prepareAndExecuteCache](/version-0.x/reference/core-classes/databaseprovider/databaseprovider-methods.md#prepareandexecutecache), you can only remove queries from cache that have been originally performed with a specific Cache key naming.

> The most usual way to cache queries and then be able to remove them whenever we need is to use a known `uniqueId` for each query, like in the example above.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cherrycake.tin.cat/version-0.x/guide/database-guide/removing-queries-from-cache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
