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:
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.