I already knew how to empty the DNS cache on Linux. What I could not do for a long time was look inside it. Newer versions of systemd can show it.
resolvectl show-cache
The manual describes it as showing the current cache content, per scope. A scope is roughly a network link or the global resolver, so the records come grouped by where they were resolved. The command is listed as added in systemd version 254, so it does not exist on an older distribution.
For something a script can read, ask for JSON:
resolvectl show-cache --json=pretty
The accepted modes are short, pretty and off. Pipe it through jq to find one name in a long list.
It is the natural next step after resolvectl statistics, which only says how often the cache is hit. If a name resolves to an address you did not expect, check whether an old answer is still sitting there before you flush it with resolvectl flush-caches.
Caveat: the cache shows the queries your machine has made, which says a lot about what you do. Read it before you paste anything into a forum.
Further reading: resolvectl(1) manual