Content caching is one of the most effective ways to significantly improve the performance of web sites. Next we will talk about nginx high-performance cache.
Basic principles of content caching
Cache GET requests.
Use: browser cache, content delivery network, and/or reverse proxy cache.
HTTP cache mechanism:
1. The content cache capability claimed by the source server. It mainly controls the http header information.
2. Client cache capability of the request, such as GET request.
What does nginx cache?
1. The cache does not have the GET and HEAD responses of the Set-Cookie.
2. Define a unique original URL, such as proxy_cache_key.
3. Define the Cache time, such as X-Accel-Expires, Cache-Control, and Expires.
Nginx operations
Nginx configuration
Cache process
Nginx can be defined using the proxy_cache_use_stale command in the following cases.
Not only does it cache HTTP, but it also has other features, such:
1. FastCGI functions are similar to HTTP
2. Memcache searches for memcached server content (must be prefilled)
3. uwsgi and SCGI
How to understand these
Cache meter
$ Upstrem_cache_status variable values include: MISS, BYPASS, EXPIRED, STALE, UPDATING, REVALDATED, and HIT.
Extended status monitoring
Cache content on nginx
How does it work?
1. nginx uses disk-based persistent cache.
2. Pay attention to the following points:
How is the content stored in the cache?
How is the cache loaded at startup?
Cache expiration pruning
Manual cleanup of cache content
How is cached content stored?
First, define proxy_cache_path.
Define cache key, proxy_cahce_key
Get the content to the cache, and then check the MD5 value
Verify
Load cache from disk
Manage disk cache
Clear disk content
Control cache
Delayed cache proxy_cache_min_uses saves disk write
Cache re-verify proxy_cache_revalidate to save upstream bandwidth and disk write
Cache time control
Multiple caches
Why cache
Increase webpage speed