Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Apache series (server cache)

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Turn on mod_cache

Cache based on hard disk files

Caching based on hard disk file storage is implemented by the mod_disk_cache module. Let's look at a simple configuration example:

CacheDefaultExpire 86400CacheEnable disk / CacheRoot / tmp/apacheCacheCacheDirLevels 5CacheDirLength 5CacheMaxFileSize 1048576CacheMinFileSize 10

Add the above configuration to the httpd.conf file of Apache, and if the cache-related modules have been compiled into the core of Apache, you can use the above instructions without loading the module. The instructions are described in detail as follows:

CacheDefaultExpire: sets the cache expiration time (in seconds). The default is 1 hour. This instruction will take effect only if the cached document does not set the expiration time or the last modification time.

CacheEnable: enable cache, the first parameter is cache class, here is disk, of course, the second parameter is cache path, which refers to url path, here is cache everything, just write "/", if "/ docs", only cache all files under / docs

CacheRoot: the directory where the cache file is located. The user running Apache (such as daemon or nobody) needs to be able to read and write to it. If it is not clear, you can directly set it to 777.Please manually establish the directory and set the access permission.

CacheDirLevels: the depth of the cache directory. Default is 3, which is set to 5 here.

CacheDirLength: the character length of the cache directory name. The default is 4, which is set to 5.

CacheMaxFileSize and CacheMaxFileSize: the maximum and minimum values of the cache file (byte). When this range is exceeded, the cache will no longer be cached, which is set to 1m and 10bytes.

These are basically the files stored on the hard disk. After setting up, restart Apache should be able to use it. If everything is all right, you can see some directories and cached data files automatically created by Apache in the cache directory.

Memory-based caching

Memory-based caching is mainly implemented by the mod_mem_cache module, so let's look at a simple configuration, which is more intuitive: -)

CacheEnable mem / MCacheMaxObjectCount 20000 MCacheMaxObjectSize 1048576 MCacheMaxStreamingBuffer 65536 MCacheMinObjectSize 10 MCacheRemovalAlgorithm GDSF MCacheSize 131072

Briefly describe the meaning of some of the above instructions:

CacheEnable: enable caching and use memory-based storage

MCacheMaxObjectCount: the maximum number of cache objects that can be stored in memory. The default is 1009, which is set to 20000 here.

MCacheMaxObjectSize: the maximum size of a single cache object is 1m. The default is 10000bytes.

MCacheMaxStreamingBuffer: the maximum size of the object to be cached in the buffer, which is set to 65536, which is usually less than the value set by 100000 or MCacheMaxObjectSize

MCacheMinObjectSize: the minimum size of a single cache object is 10bytes, and the default is 1bytes

MCacheRemovalAlgorithm: the algorithm used to clear the cache. The default is GDSF, and the other is LRU. You can check the official documentation of Apache, as described above.

MCacheSize: the maximum memory that can be used for caching data (in kb). The default is 100kb, which is set to 128m here.

Saving and restarting the Apache memory-based caching system should work, and memory-based storage or hard disk file storage can be used together as needed, as long as a different URL path is specified.

Matters needing attention

You need to be aware of the following when using caching:

To use caching, you must use the instruction CacheEnable to enable it. Currently, the available cache type is disk or mem, and CacheDisable can be used to prohibit caching, such as CacheDisable / private.

The status value returned by the URL to be cached must be 200,203,300,301 or 410

The request method of URL must be GET.

When sending a request, when the header contains a string of "Authorization:", the returned content will not be cached

URL contains query strings, such as question marks? Those things will not be cached unless the returned content contains "Expires:"

If the returned status value is 200, the returned header information must contain one of the following types: Etag, Last-Modified, Expires, unless the instruction CacheIgnoreNoLastMod On is set

If the header message "Cache-Control:" of the returned content contains "private", it will not be cached unless the instruction CacheStorePrivate On is set.

If the header message "Cache-Control:" of the returned content contains "no-sotre", it will not be cached unless the instruction CacheStoreNoStore On is set.

If the header information "Vary:" of the returned content contains "*", it will not be cached

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report