What is Selective Caching? | Cache Key Optimization for CDN

Learn what Selective Caching is, how it optimizes cache keys to determine what gets cached and with what criteria, and when to use it for intelligent content delivery.

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

StrategyQuestion it answersFocus
Micro CachingHow long to cache?Short TTL for dynamic data
Tiered CachingHow many layers to cache?Hierarchy between points of presence and origin
Granular CachingWhat to cache and with what rule?Segmentation by headers and cookies
Selective CachingWhich 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 TypeCache BehaviorTypical TTL
Static assets (images, CSS, JS)Always cacheDays to weeks
Product catalogCache with invalidationHours
API responsesSelective by endpointSeconds to minutes
User-specific dataCache with session keySeconds
Payment operationsNever 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 TTL

Cache 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 URL
GET /api/products/{id} → Cache 2 minutes, key by URL + Accept-Language
GET /api/cart/* → Cache 30 seconds, key by session_id
GET /api/recommendations/* → Cache 1 minute, key by user_segment
POST /api/cart/* → Bypass cache
POST /api/payment/* → Bypass cache
POST /api/orders/* → Bypass cache

Result:

  • 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.

Talk to an Azion specialist

stay up to date

Subscribe to our Newsletter

Get the latest product updates, event highlights, and tech industry insights delivered to your inbox.