# negative cache

> cache used to remember failed or missing responses

**Wikidata**: [Q6987201](https://www.wikidata.org/wiki/Q6987201)  
**Wikipedia**: [English](https://en.wikipedia.org/wiki/Negative_cache)  
**Source**: https://4ort.xyz/entity/negative-cache

## Summary
A negative cache is a computing component that stores failed or missing responses to improve system performance. It transparently remembers unsuccessful requests so that future attempts for the same non-existent or unavailable data can be served faster without repeating the same failed lookup. This is a specialized form of caching that handles absence rather than presence of data.

## Key Facts
- Classified as a subclass of cache with the qualifier "absence" indicating it specifically handles missing data
- Different from a cache miss, which is a lookup failure rather than a stored negative response
- Has Wikipedia articles in English and Hungarian languages
- Freebase ID: /m/01h_wm
- Microsoft Academic ID: 2776861477 (discontinued)
- Wikidata sitelink count: 2
- Parent class: cache (computing component that transparently stores data for faster future requests)
- Wikipedia title: Negative cache
- Wikidata description: "cache used to remember failed or missing responses"

## FAQs
### Q: What is the difference between a negative cache and a regular cache?
A: A regular cache stores successful responses to serve them faster in the future, while a negative cache stores failed or missing responses to prevent repeated unsuccessful lookups. Both are types of caching, but they handle opposite outcomes of data requests.

### Q: Why would you want to cache failed responses?
A: Caching failed responses prevents the system from repeatedly attempting to retrieve data that doesn't exist or is unavailable, saving resources and improving performance. It's particularly useful for DNS lookups, database queries, and API calls that consistently fail.

### Q: Is a negative cache the same as a cache miss?
A: No, a negative cache is different from a cache miss. A cache miss occurs when requested data isn't found in the cache, while a negative cache is an intentional storage of failed responses to prevent future lookup attempts.

## Why It Matters
Negative caching plays a crucial role in optimizing system performance and resource utilization in distributed computing environments. By remembering failed requests, it prevents systems from wasting computational resources on repeated lookups for non-existent or unavailable data. This is particularly valuable in scenarios like DNS resolution, where repeatedly querying for non-existent domains would create unnecessary network traffic and server load. Negative caching also improves user experience by providing immediate feedback on failed requests rather than making users wait for timeouts. In microservices architectures and large-scale web applications, negative caching helps maintain system stability by reducing the load on backend services and preventing cascading failures. The technique is essential for building resilient, efficient systems that can gracefully handle missing or unavailable resources without degrading overall performance.

## Notable For
- Specialized caching mechanism that handles absence of data rather than presence
- Prevents repeated failed lookups, saving computational resources
- Improves system performance by providing immediate feedback on unavailable resources
- Essential component in DNS and distributed systems architectures
- Distinguishes between intentional storage of failed responses versus accidental cache misses

## Body
### Technical Implementation
Negative caching is typically implemented through time-to-live (TTL) values that determine how long failed responses should be stored. When a request fails, the system stores the negative response along with an expiration time. During subsequent requests within the TTL period, the system immediately returns the cached negative response without attempting the original operation again.

### Common Use Cases
Negative caching is widely used in DNS servers to prevent repeated queries for non-existent domain names. It's also employed in web applications to cache 404 responses, in database systems to remember failed queries, and in API gateways to store failed authentication attempts. Content delivery networks (CDNs) use negative caching to handle requests for non-existent content efficiently.

### Performance Benefits
The primary benefit of negative caching is reduced latency for failed requests. Instead of waiting for a timeout or multiple retry attempts, users receive immediate feedback. This also reduces network traffic, server load, and database queries for non-existent resources. In high-traffic systems, these savings can be substantial.

### Configuration Considerations
Effective negative caching requires careful configuration of TTL values. Too short a TTL may not provide sufficient benefit, while too long a TTL could prevent legitimate data from becoming available. Systems must also handle cache invalidation properly when resources that were previously unavailable become available again.