Selective Caching determines what should be cached based on specific criteria — optimizing cache keys to ensure the right content is cached with the right rules for intelligent content delivery.
What is Selective Caching?
Selective Caching — also called advanced cache or granular cache — is the ability to define what should be cached based on specific HTTP request information.
Unlike “all or nothing” caching, Selective Caching uses Advanced Cache Keys to determine:
- What content should be cached
- With what criteria the cache key should be built
- When content should bypass cache entirely
This technique answers a specific question: “With what selection criteria should I cache this content?”
How Selective Caching works
Selective Caching operates by applying rules that determine cache behavior for each request:
1. Cache eligibility check Should this request be cached at all? Some content (payment authorization, order finalization) should never be cached.
2. Cache key construction What combination of URL, headers, cookies, and query strings uniquely identifies this content?
3. TTL assignment How long should this content be cached? Different content types need different cache durations.
4. Bypass rules When should cache be explicitly bypassed regardless of other rules?
Selective Caching vs. other caching strategies
| Strategy | Question it answers | Focus |
|---|---|---|
| Micro Caching | How long to cache? | Short TTL for dynamic data |
| Tiered Caching | How many layers to cache? | Hierarchy between points of presence and origin |
| Granular Caching | What to cache and with what rule? | Segmentation by headers and cookies |
| Selective Caching | Which criteria to use? | Cache key optimization |
All four strategies are complementary — not mutually exclusive.
Cache key optimization
What is a cache key?
A cache key is a unique identifier that determines whether a cached response exists for a specific request. The cache key is built from:
- URL path — the basic identifier
- Query strings — parameters that affect content
- Headers — device type, language, encoding
- Cookies — session or preference identifiers
Optimizing cache keys
Too broad — Cache key includes only URL
- Result: Same content for all users, potential session contamination
Too narrow — Cache key includes too many variables
- Result: Cache fragmentation, low hit ratio, wasted storage
Optimal — Cache key includes only variables that affect content
- Result: High hit ratio, correct personalization, efficient storage
Selective Caching rules
Cache by content type
Different content types have different caching requirements:
| Content Type | Cache Behavior | Typical TTL |
|---|---|---|
| Static assets (images, CSS, JS) | Always cache | Days to weeks |
| Product catalog | Cache with invalidation | Hours |
| API responses | Selective by endpoint | Seconds to minutes |
| User-specific data | Cache with session key | Seconds |
| Payment operations | Never cache | — |
Cache by endpoint
Apply different rules to different API endpoints:
/api/products → Cache with 5-minute TTL/api/cart → Cache with session key, 30-second TTL/api/payment/authorize → Bypass cache entirely/api/recommendations → Cache by user segment, 1-minute TTLCache by user segment
Different user segments may receive different cached content:
- Anonymous users — Shared cache, longer TTL
- Authenticated users — Session-specific cache, shorter TTL
- Premium users — Personalized cache, minimal TTL
When to use Selective Caching
Use Selective Caching when:
- Different endpoints need different cache behaviors
- Content varies by user segment, device, or location
- You need fine-grained control over what gets cached
- Some operations must never be cached
- You’re implementing intelligent content delivery
Avoid Selective Caching when:
- All content is static and identical for all users
- Cache rules would be too complex to maintain
- The overhead of rule evaluation outweighs the benefit
Combining Selective Caching with other strategies
Selective Caching works best when combined with other caching strategies:
With Micro Caching: Selective Caching determines what to cache; Micro Caching determines how long.
With Tiered Caching: Selective Caching determines cache rules; Tiered Caching determines cache distribution.
With Granular Caching: Selective Caching determines selection criteria; Granular Caching implements the segmentation.
Best practices for Selective Caching
1. Define clear cache eligibility rules
Explicitly document which content should and shouldn’t be cached. When in doubt, start with conservative rules and expand.
2. Use consistent cache key construction
Define a standard order for cache key components to ensure consistency across your infrastructure.
3. Implement explicit bypass rules
Never rely on implicit behavior for critical operations. Explicitly define bypass rules for payment, authentication, and other sensitive operations.
4. Monitor cache effectiveness
Track cache hit ratios by rule to identify over-caching or under-caching situations.
5. Plan for invalidation
Define how cache will be invalidated when content changes — key-based purge, time-based expiration, or event-driven invalidation.
Real example: e-commerce API caching
An e-commerce platform uses Selective Caching for their API:
Cache rules:
GET /api/products/* → Cache 5 minutes, key by URLGET /api/products/{id} → Cache 2 minutes, key by URL + Accept-LanguageGET /api/cart/* → Cache 30 seconds, key by session_idGET /api/recommendations/* → Cache 1 minute, key by user_segmentPOST /api/cart/* → Bypass cachePOST /api/payment/* → Bypass cachePOST /api/orders/* → Bypass cacheResult:
- Product browsing is fast and scalable
- Cart operations remain responsive
- Payment operations are never cached
- Recommendations are personalized but efficient
FAQ
What is Selective Caching?
It’s a caching technique that determines what should be cached based on specific criteria, optimizing cache keys for intelligent content delivery.
How is Selective Caching different from basic caching?
Basic caching typically caches everything or nothing. Selective Caching applies rules to determine what gets cached, with what key, and for how long.
What’s the difference between Selective Caching and Granular Caching?
Selective Caching focuses on determining which criteria to use for caching decisions. Granular Caching focuses on implementing the segmentation with Advanced Cache Keys. They work together.
When should I use Selective Caching?
Use it when different content types or endpoints need different cache behaviors, or when some operations must never be cached.
How does Selective Caching relate to cache bypass?
Selective Caching includes explicit bypass rules that ensure certain operations (like payment authorization) never go through cache, regardless of other configuration.
Can Selective Caching improve cache hit ratio?
Yes, by ensuring only appropriate content is cached with optimal keys, Selective Caching can significantly improve cache hit ratio compared to blanket caching policies.
Conclusion
Selective Caching provides the intelligence layer for your caching strategy. By determining what should be cached and with what criteria, it ensures that cache is used effectively without compromising data integrity or user experience.
Combined with Micro Caching for freshness, Tiered Caching for distribution, and Granular Caching for segmentation, Selective Caching enables sophisticated caching strategies that deliver the right content to the right user at the right time.
Next steps
Check out Azion’s Cache solution and see how it implements Selective Caching for intelligent content delivery.