Skip to content

Commit 73f1e4f

Browse files
committed
+ Improving Varnish Cache Hit Rate
1 parent d6d0adc commit 73f1e4f

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
myst:
3+
html_meta:
4+
description: Learn how to improve your Varnish cache hit rate on Hypernode by identifying automatic cache purges, analyzing hit/miss patterns, and optimizing URL normalization to boost performance and efficiency.
5+
title: Improving Varnish Cache Hit Rate on Hypernode
6+
---
7+
8+
# Improving Varnish Cache Hit Rate
9+
10+
An improved **Varnish hit rate** ensures that more pages are served directly from cache. This reduces backend resource usage on your Hypernode and allows your shop to handle more concurrent visitors without performance degradation.
11+
A low hit ratio usually indicates a caching misconfiguration or cache invalidation happening too frequently.
12+
13+
---
14+
15+
## Understanding Cache Hit Rate
16+
17+
- **HIT:** The response is served directly from Varnish cache
18+
- **MISS:** The request is forwarded to the backend (for example, PHP/Magento)
19+
20+
A consistently low hit rate means that:
21+
22+
- Pages are bypassing Varnish
23+
- Cache entries are being purged too often
24+
- URLs are fragmented due to parameters or inconsistencies
25+
26+
---
27+
28+
## Common Issue: Automatic Cache Busting
29+
30+
If you notice that your cache is cleared at consistent times, this often points to an automated process that flushes the cache.
31+
32+
### Typical causes
33+
34+
- External integrations that frequently update stock or pricing
35+
- Magento cron jobs triggering full cache purges
36+
- Extensions that invalidate more cache than necessary
37+
38+
### What to do
39+
40+
- Review all third-party integrations that update catalog or pricing data
41+
- Inspect Magento cron jobs for full cache invalidation tasks
42+
- Reduce the scope or frequency of full cache purges
43+
- Prefer targeted purges (specific URLs or entities) instead of clearing the entire cache
44+
45+
---
46+
47+
## Checking Cacheability and Hit/Miss Behavior
48+
49+
When Varnish is frequently purged or bypassed, your hit rate will drop. You can analyze this behavior using the tools below.
50+
51+
### Useful tools
52+
53+
#### `varnishlog`
54+
View detailed logs of Varnish requests and responses. Look for recurring **MISS** patterns on URLs that should be cacheable.
55+
56+
#### `varnishstat`
57+
Provides counters for cache hits, misses, and backend requests.
58+
59+
#### Hypernode Insights (if available)
60+
Use hit/miss graphs to identify when cache invalidations occur and correlate them with deployments or cron activity.
61+
62+
---
63+
64+
## Checking Varnish Headers Using cURL
65+
66+
You can verify whether a page is cached directly from your own terminal.
67+
68+
```bash
69+
curl -I https://www.example.com/ \
70+
| egrep 'Age:|Via:|X-Cache|X-Magento-Cache-Debug|Cache-Control'
71+
```
72+
73+
### What to look for
74+
75+
- **Age** header increasing → cached response
76+
- **X-Cache: HIT** → served from Varnish
77+
- **Cache-Control** headers that allow caching
78+
- Absence of **Set-Cookie** for cacheable pages
79+
80+
---
81+
82+
## Checking Cache Statistics on Your Hypernode
83+
84+
### Snapshot of hits and misses
85+
86+
Untested example (single run):
87+
88+
```bash
89+
varnishstat -1 -f MAIN.cache_hit,MAIN.cache_miss,MAIN.backend_req
90+
```
91+
92+
### Tested (live overview of cached URLs)
93+
94+
```bash
95+
varnishncsa -F '%U%q %{Varnish:hitmiss}x' | grep hit
96+
```
97+
98+
This helps identify which URLs are effectively cached and which are not.
99+
100+
---
101+
102+
## Handling Marketing and Tracking URL Parameters
103+
104+
Marketing parameters such as `utm_source`, `utm_medium`, or `gclid` can dramatically increase the number of unique cache entries.
105+
Each parameter variation creates a new cache object, lowering your overall hit rate.
106+
107+
### Best practice
108+
109+
Normalize URLs so that these parameters do not influence caching decisions.
110+
111+
#### Examples of parameters to strip
112+
113+
- `utm_*`
114+
- `gclid`
115+
- `fbclid`
116+
117+
This normalization should happen before Varnish decides whether a request is cacheable.
118+
119+
> **Tip:** The [`elgentos/magento2-varnish-extended`](https://github.com/elgentos/magento2-varnish-extended) extension improves handling of marketing parameters and enhances the default Magento 2 VCL.
120+
121+
---
122+
123+
## URL Normalization
124+
125+
Different URL variations can fragment your cache and reduce efficiency.
126+
127+
### Common normalization examples
128+
129+
- **Trailing slashes**
130+
`/category``/category/`
131+
- **Lowercase query parameters**
132+
`?Color=Red``?color=red`
133+
- **Remove session IDs or irrelevant parameters**
134+
135+
By normalizing URLs, similar requests map to the same cache object, reducing duplication and improving hit rates.

0 commit comments

Comments
 (0)