Home > php教程 > PHP开发 > apache uses mod_cache to cache images, etc.

apache uses mod_cache to cache images, etc.

黄舟
Release: 2016-12-21 11:38:04
Original
1326 people have browsed it

1. Introduction

I have written two articles about caching images and static files before. One is caching using varnish, and the other is caching using squid. Of course, apache can also be used to cache images and static files. Below I will I will explain in detail how to complete the installation and configuration

Second, install mod_cache, mod_mem_cache, mod_disk_cache

First check whether these modules are installed when installing apache. If not, install them. Please refer to how to install modules in apache , check whether it is installed

[zhangy@BlackGhost error]$ /usr/local/apache2/bin/httpd -l

If there is no mod_cache.c, mod_mem_cache.c, mod_disk_cache.c, it means that mod_mem_cache and mod_disk_cache are not installed. Install, you can choose one of the two

Three, memory cache configuration

nano /usr/local/apache2/conf/httpd.conf

LoadModule cache_module modules/mod_cache.so

LoadModule mem_cache_module modules/mod_mem_cache.so

CacheEnable mem /images
MCacheSize 4096
MCacheRemovalAlgorithm LRU
MCacheMaxObjectCount 100
MCacheMinObjectSize 1
MCacheMaxObjectSize 204 8
CacheMaxExpire 864000
CacheDefaultExpire 86400
CacheDisable /php


Instructions:

1. CacheEnable mem /images caches the content below images. Mem here is just a cache type that instructs mod_cache to use the memory storage manager by implementing mod_mem_cache. The cache type disk instructs mod_cache to use the disk-based storage management implementation of mod_disk_cache. Cache type, fd instructs mod_cache to use the file descriptor cache implementation mod_mem_cache

2, MCacheSize maximum memory usage, objects inserted in the cache and the object size is larger than the remaining memory will be deleted until new objects can be cached. The deleted objects are selected using the specified algorithm MCacheRemovalAlgorithm

3, MCacheRemovalAlgorithm caching algorithm:

LRU (Least Recently Used)

LRU deletes files without the longest time accessed.

GDSF (GreadyDual Size)

GDSF allocates a priority file cache based on file charges, cache size and misses. Files with lowest priority are deleted first.

4 The default cache expiration time

9, CacheDisable /php does not cache the content under php

Check whether the memory has cached things

apache to check whether there is anything cached in the memory, it is not easy to check, there is no special tool to check , my method is as follows,

1, browse the picture http://localhost/images/http_imgload.cgi.jpeg

2, check [zhangy@BlackGhost error]$ top -b -n1

3, browse the picture http ://localhost/images/myself.jpeg

4, check [zhangy@BlackGhost error]$ top -b -n1

6018 zhangy 20 0 52612 8172 2484 S 0 0.8 0:00.03 httpd

6020 zhangy 20 0 52604 8168 2488 S 0 0.8 0:00.02 httpd

6021 zhangy 20 0 52604 8100 2440 S 0 0.8 0:00.00 httpd

6022 zhangy 20 0 52604 81 00 2440 S 0 0.8 0:00.00 httpd

6033 zhangy 20 0 6584 1808 1396 S 0 0.2 0:00.02 bash

6076 zhangy 20 0 52612 8136 2464 S 0 0.8 0:00.02 httpd

6077 zhangy 20 0 52612 8124 2448 S 0 0.8 0: 00.05 httpd

6078 zhangy 20 0 52612 8168 2488 S 0 0.8 0:00.12 httpd

6079 zhangy 20 0 52612 8168 2488 S 0 0.8 0:00.03 httpd

6080 zhangy 20 0 52612 8168 2488 S 0 0.8 0:00.06 httpd
60 81 zhangy 20 0 52612 8116 2448 S 0 0.8 0:00.00 httpd

via 4 above Following the step-by-step operation, you can find that the RES in bold above is constantly increasing. From this, it can be seen that the configuration has been successful.

Four, hard disk cache configuration

nano /usr/local/apache2/conf/httpd.conf

LoadModule cache_module modules/mod_cache.so

LoadModule disk_cache_module modules/mod_disk_cache.so

CacheRoot /home/zhangy/cachetest
#CacheSize 2 56
CacheEnable disk/
CacheDirLevels 4
#CacheMaxFileSize 64000
#CacheMinFileSize 1
#CacheGcDaily 23:59
CacheDirLength 3


Description:

1, cacheroot /home/zhangy/cachetest directory where the cache is stored

2, #CacheSize 256 Cache space size unit KB

3, CacheEnable disk / Set cache mode

4, #CacheMaxFileSize 64000 Maximum cache file size

5, #CacheMinFileSize 1 Minimum cache file size

6, #CacheGcDaily 23:59 Cache cleanup time

7, CacheDirLength 3 Cache folder name sub-character length

8, CacheDirLevels 4 Cache directory, subdirectory level

The commented out part is not supported by my apache version. It's in the official manual. For specific requirements, please refer to the official website

Check cache:

1. Check if there is anything in cacheroot

apache cache

If there is something under CacheRoot, it means it is OK.

2, use htcacheclean to view

[root@BlackGhost cache]# /usr/sbin/htcacheclean -v -p /home/zhangy/cachetest -l 1024M
Statistics:
size limit 1024.0M
total size was 29.2K , total size now 29.2K
total entries was 3, total entries now 3

htcacheclean Some parameter descriptions

-d How often to clear the cache

-D simulates clearing the cache, but it is not really clear

-v Display statistics

-r Completely clear

-t Clear empty directories

-p Cache directory

-l Limit cache size

The above is the content of apache using mod_cache to cache images, etc. Please pay attention to more related content PHP Chinese website (www.php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template