You can flush the local DNS cache with the following command:
dscacheutil -flushcache
How long a DNS entry is cached typically depends on the TTL of that DNS record, which is configured by the DNS admin of the relevant hostname.
You can find out the (remaining) TTL of any given DNS record with the dig
command:
dig apple.stackexchange.com
In the answer section you'll see the remaining TTL right next to the hostname (in this example 257 seconds).
;; ANSWER SECTION:
apple.stackexchange.com. 257 IN A 198.252.206.16
The effect you're seeing has absolutely nothing to do with the caches on your computer.
Instead what you're seeing is that your recursive DNS server (i.e. typically your ISPs DNS server or Google DNS or similar) has taken the original TTL value and subtracted the amount of time passed since it retrieved these records from the authoritative DNS server.
For example let's say that you own example.com and have an authoritative DNS server set up that when queried gives you that CNAME with a TTL of 86400. Then at some random point in time, your ISPs recursive DNS server is asked by someone else for www.example.com and retrieves those records. It caches that information.
Now you come along issuing the dig command without the @ parameter - this means that the request uses the server listed in /etc/resolv.conf, which is typically your ISPs recursive DNS server. Now you get the response back with TTL 83995, which means that 86400-83995=2405 seconds has passed since it originally retrieved those records.
Nowhere in this process is your standard, local macOS DNS cache involved, so mDNSResponder and dscacheutil is not going to change anything at all.
The reasoning behind this is that the authoritative DNS server has essentially stated that "this information is valid for 86400 seconds". The recursive DNS doesn't know if the authoritative DNS server has since been changed to give out new information, so it can only tell you that the information is now valid for a slightly smaller amount of time.
Best Answer
Use
or
In 10.6 the handling of Unicast DNS is now managed by mDNSResponder -
dscacheutil -flushcache
now just tells mDNSResponder to restart (the second command above).