You can manually remove a cached query from cache before its natural TTL-driven expiration time by using the DatabaseProvider::clearCacheQuery method, here's an example:
$e->Database->main->clearCacheQuery(["uniqueId" => "usersSignedUpLast24Hours"]);
Because query cache keys are automatically generated if you don't specify any Cache key naming when calling methods like DatabaseProvider::queryCache and DatabaseProvider::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
uniqueIdfor each query, like in the example above.