Today I Learned - Rocky Kev

TIL about Negative Caching

POSTED ON:

TAGS:

If you're ever working on a site and get a "Server Not Found", then fix it (so that it totally works), and you STILL get a "Server Not Found"?

That's called Negative caching!

How long does it live?

The TTL for negative caching is not arbitrary. It is taken from the SOA record at the top of the zone to which the requested record would have belonged, had it existed.

via This StackExchange answer

I learned about this on this sweet DNS sandbox https://messwithdns.net/

I hope this site still works. I saw things changing from even a year ago.

Weird Experiment #1:

Did you know that just visiting a domain can make it not work? This is weird but true! In this experiment, we'll:

Create a DNS record for a subdomain, and then visit it after (this will work!)

Visit a subdomain, and create the DNS record for it, and then visit it again (this won't work!)

Let's go!

  1. Create a CNAME record with
Name: visit-after
Type: CNAME
Target: orange.jvns.ca
TTL: 3600
  1. Go to visit-after.shark98.messwithdns.com in your browser. You should see an orange site -- everything works!

  2. Now, go to visit-before.shark98.messwithdns.com in your browser. You should get an error like "Server Not Found", since we haven't created the record yet.

  3. Create a CNAME record with:

Name: visit-before
Type: CNAME
Target: orange.jvns.ca
TTL: 3600

With visit-before, it doesn't work because of something DNS resolvers do called negative caching, where they cache the absence of a record.

You create record

Not all DNS resolvers do negative DNS caching! For example, Cloudflare doesn't, so this experiment won't work for you if you're using Cloudflare DNS!

Here's the full instructions in case the site changed: 2022-04-19-negative-caching_0.png


Related TILs

Tagged:

TIL of what happens when you put a random url in your DNS records

So when you use a 'A' record, it points to the IP address. If you put a site you don't own, and it gets redirects, it'll 404 because the header metadata!

TIL about Negative Caching

If you're ever working on a site and get a 'Server Not Found', then fix it (so that it totally works), and you STILL get a 'Server Not Found', that's negative catching!

TIL about Negative Caching

If you're ever working on a site and get a 'Server Not Found', then fix it (so that it totally works), and you STILL get a 'Server Not Found', that's negative catching!