> For the complete documentation index, see [llms.txt](https://cherrycake.tin.cat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cherrycake.tin.cat/version-1.x-beta/guide/database-guide/removing-queries-from-cache.md).

# 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-1.x-beta/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-1.x-beta/guide/database-guide/cache-key-naming.md) when calling methods like [DatabaseProvider::queryCache](/version-1.x-beta/reference/core-classes/databaseprovider/databaseprovider-methods.md#querycache) and [DatabaseProvider::prepareAndExecuteCache](/version-1.x-beta/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.
