Apache Module Mod_cache Application

Source: Internet
Author: User

Mod_cache is a URI key-based content dynamic buffer ( memory or disk ) in Apache

apache2.2 Mod_cache and Mod_file_cache will no longer be test modules, they are stable enough to be used in real production. These buffering systems provide a powerful way to accelerate the original web server (origin webserver) and Proxy server http processing speed.

Mod_cache and its support modules Mod_mem_cache and Mod_disk_cache provide intelligent buffer. Content itself is stored in a buffer, mod_ The purpose of the cache is to manage various

On the other hand, Mod_file_cache implements a more basic, but in some cases, more efficient form of buffering, which avoids the maintenance complexity required to proactively ensure the URL buffering capability, Mod_file_cache by providing a file handle ( File-handle) and Memory mapping (memory-mapping) techniques to maintain a file buffer since Apache last started. Similarly, the goal of Mod_file_cache is to improve access times for infrequently modified local static files.

Since Mod_file_cache provides a relatively simple buffer implementation, the instructions for this guide cover the Mod_cache cache architecture in addition to the specific paragraphs of cachefile and mmapstatic documents.

Install compile

In order to be able to use the cache in Apache , you need to add the following parameters when installing compile.

--enable-cache--enable-disk-cache--enable-mem-cache--enable-file-cache

[Email protected] httpd-2.4.1]#/configure--prefix=/usr/local/apache2worker--enable-so  --enable-cache   --enable-disk-cache--enable-mem-cache  --enable-file-cache[[email protected] httpd-2.4.1]# Make[[email Protected] httpd-2.4.1]# make install

Two modes of caching:

Mod_disk_cache

A disk-based storage management module.

Mod_mem_cache

A memory-based storage management module. Mod_mem_cache can be configured to two different modes of operation:① caches open file descriptors,② caches objects on heap. Mod_mem_cache can either be used to cache locally generated content or for Mod_proxy cache back-end server output for reverse proxy mode.

Hard disk file-based caching

The cache based on hard disk file storage is implemented by the mod_disk_cache module:

<mod_cache.c>
Cachedefaultexpire 3600CacheMaxExpire 86400CacheLastModifiedFactor 0.1
<mod_disk_cache.c>cacheroot/usr/local/apache/cachecacheenable disk/cachedirlevels 5CacheDirLength 3CacheMaxFileSize 10000000CacheMinFileSize 1</ifmodule
</ifmodule>

Copy the above content into Apache 's httpd.con file:

Search in the httpd.conf file

#LoadModule cache_module modules/mod_cache.so// Remove the previous #

Use Disk File caching:

#LoadModule disk_cache_module modules/mod_disk_cache.so// Remove the previous #

The parameters have the following meanings :

Cachedefaultexpire:

Set the cache expiration time (in seconds) by default of 1 hours, which will only take effect if the cached document does not have an expiration time set or the last modification time.

Cachemaxexpire:

The maximum value of the expiration period, the default expiration period for the cache entity is one hour (3600 seconds ), and this default value is only used when the original resource that generated the content does not explicitly specify the expiration time or the last modification time.

Cachelastmodifiedfactor:

The expiration time is not provided in the file for the event, and a factor specified by the directive is used to generate the due date. For example, if the file was last modified ten hours ago and the coefficient is 0.1, then the expiration period will be set to ten * 0.1 = 1 hours If the current time is p.m., and then the expiry time is calculated 3:00+1 hours, which is 4:00 in the afternoon, if the expiry time is greater than cachemaxexpire, then the latter has a higher priority.

-----------------------------------------

CacheRoot:

The directory where the cache file resides, the user running Apache (such as daemon or nobody) can read and write to it, and if it is not clear, it can be set directly to 777, please manually establish the directory and set the access rights.

Cacheenable:

Enable the cache, the 1th parameter is the cache class, here is the disk, the 2nd parameter is the cache path, refers to the URL path, here is the cache of everything, directly write "/", such as "/docs" only cache all files under/docs

Cachedirlevels:

Cache directory Depth, default is 3, here set to 5

Cachedirlength:

The character length of the cache directory name, default is 4, here is set to 5

Cachemaxfilesize and Cachemaxfilesize:

The maximum and minimum value (byte) of the cached file, which is no longer cached when this range is exceeded, is set to 1M and 10bytes

Files based on hard disk file storage basically this content, set up after the restart Apache should be able to use. All normal, you can see in the cache directory Apache automatically established some directories and cached data files.

Memory-based caching

Memory-based caching is primarily implemented by the Mod_mem_cache module:

<mod_cache.c><mod_mem_cache.c>cacheenable mem/mcachesize 4096MCacheMaxObjectCount 2000MCacheMinObjectSize 1MCacheMaxObjectSize 2048</ifmodule>
</ifmodule>

After the installation is complete, you need to search

LoadModule cache_module modules/mod_cache.so// Remove the front #

Use memory file cache:

#LoadModule mem_cache_module modules/mod_mem_cache.so// Remove the previous #

The parameters have the following meanings:

Cacheenable:

Enable caching, using memory-based storage

Mcachesize:

Cache data can use up to the memory, in kilobytes, the default is 100KB, here is set to 128M

Mcachemaxobjectcount:

The maximum number of cache objects can be stored in memory, the default is 1009, this is set to 20000

Mcacheminobjectsize:

A single Cache object with a minimum of 10bytes and a default of 1bytes

Mcachemaxobjectsize:

A single Cache object is up to 1M, and the default is 10000bytes

Save restart Apache The memory-based cache system should work, as needed, to make memory-based storage or hard disk file storage available together, as long as you specify a different URL path.

-----------------------------------

Learning here, Apache's content is first over, follow-up learning Tomcat application services.

Apache Module Mod_cache Application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.