#The Apache HTTP server provides a range of caching features designed to improve server performance in various ways.
## RFC2616 HTTP cache (Recommended Learning: Apache server )
## MOD_CACHE and its provider module MOD_CACHE_DISK provides provided provided Smart HTTP-aware caching. The content itself is stored in the cache, and mod_cache is designed to respect all the various HTTP headers and options that control the cacheability of the content. mod_cache targets both simple and complex cache configurations where you can handle proxy content, dynamic local content, or where you need to speed up access to local files on a potentially slow disk.Dual-State Key/Value Shared Object Cache
The Shared Object Cache API (socache) and its provider module provide server-wide key/value shared object caching. These modules are designed to cache low-level data such as SSL sessions and authentication credentials. The backend allows data to be stored server-wide in shared memory, or within the data center in a cache such as memcache or distcache.Specialized file cache
mod_file_cache provides the ability to preload files into memory at server startup and can improve access times and save frequently accessed files file handle because there is no need to go to disk on every request.Tri-State RFC2616 HTTP Cache
The HTTP protocol contains built-in support for the inline caching mechanism described in RFC2616 section 13, and the mod_cache module can be used to take advantage of this functionality. Unlike a simple two-state key/value cache, where content completely disappears when it is no longer fresh, HTTP caching includes mechanisms to retain stale content and ask the origin server whether this stale content has changed, and if not Then refresh again.Entries in the HTTP cache exist in one of three states:
Fresh
If the content is new enough (than Its fresh life is younger), it is considered Fresh. HTTP caching can serve new content for free without making any calls to the origin server.Stale
If the content is too old (earlier than its freshness life cycle), it is considered Stale. HTTP caches should contact the origin server and check if the content is still fresh before serving stale content to the client. If the origin server is still invalid, the origin server will respond with the replacement content or, ideally, the origin server will respond with a code to tell the cache that the content is still new without having to generate or send the content again . The content becomes new again and the cycle continues. The HTTP protocol allows caches to serve stale data in certain situations, such as when a 5xx error occurs when trying to refresh the data using the origin server, or another request is already in the process of refreshing a given entry. In these cases, a warning header is added to the response.Non Existent
If the cache is full, retains the option to remove content from the cache to make space. Content can be deleted at any time and can be old or new. The htcacheclean tool can be run once, or deployed as a daemon to keep the size of the cache within a given size or a given number of inodes. The tool will try to delete old content before trying to delete new content.The above is the detailed content of How to use the caching function of Apache HTTP Server. For more information, please follow other related articles on the PHP Chinese website!