PHP缓存都是哪些数据 php缓存都是哪些数据类型

深入Nginx + PHP 缓存详解以下是对Nginx中的PHP缓存进行了详细的分析介绍 需要的朋友可以参考下
Nginx缓存nginx有两种缓存机制:fastcgi_cache和proxy_cache下面我们来说说这两种缓存机制的区别吧 proxy_cache 作用是缓存后端服务器的内容 可能是任何内容 包括静态的和动态的fastcgi_cache 作用是缓存fastcgi生成的内容 很多情况是php生成的动态内容proxy_cache 缓存减少了nginx与后端通信的次数 节省了传输时间和后端带宽fastcgi_cache 缓存减少了nginx与php的通信次数 更减轻了php和数据库的压力proxy_cache 缓存设置
复制代码代码如下: #注 proxy_temp_path和proxy_cache_path指定的路径必须在同一分区 proxy_temp_path /data /proxy_temp_dir; #设置Web缓存区名称为cache_one 内存缓存空间大小为 MB 天没有被访问的内容自动清除 硬盘缓存空间大小为 GB proxy_cache_path /data /proxy_cache_dir levels= : keys_zone=cache_one: m inactive= d max_size= g; server { listen ; server_name yourdomain ; index index index ; root /data /htdocs/; location / { #如果后端的服务器返回 执行超时等错误 自动将请求转发到upstream负载均衡池中的另一台服务器 实现故障转移 proxy_next_upstream _ _ error timeout invalid_header; proxy_cache cache_one; #对不同的HTTP状态码设置不同的缓存时间 proxy_cache_valid h; #以域名 URI 参数组合成Web缓存的Key值 Nginx根据Key值哈希 存储缓存内容到二级缓存目录内 proxy_cache_key $host$uri$is_args$args; proxy_set_header Host $host; proxy_set_header X Forwarded For $remote_addr; proxy_pass //backend_server; expires d; } #用于清除缓存 假设一个URL为 通过访问就可以清除该URL的缓存 location ~ /purge(/ *) { #设置只允许指定的IP或IP段才可以清除URL缓存 allow ; allow / ; deny all; proxy_cache_purge cache_one $host$ $is_args$args; } #扩展名以 php jsp cgi结尾的动态应用程序不缓存 location ~ * (php|jsp|cgi)?$ { proxy_set_header Host $host; proxy_set_header X Forwarded For $remote_addr; proxy_pass //backend_server; } access_log off; } }
fastcgi_cache缓存设置
复制代码代码如下: #定义缓存存放的文件夹 fastcgi_cache_path /tt/cache levels= : keys_zone=NAME: m inactive= d max_size= G; #定义缓存不同的url请求 fastcgi_cache_key "$scheme$request_method$host$uri$arg_filename$arg_x$arg_y"; server { listen ; server_name example ; location / { root /; index index index index php; } location ~ (| php)$ { root /; fastcgi_pass : ; fastcgi_cache NAME; fastcgi_cache_valid h; fastcgi_cache_min_uses ; fastcgi_cache_use_stale error timeout invalid_header _ ; fastcgi_index index php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi conf; #设置缓存的过程中发现无法获取cookie 经查需要定义这句话 fastcgi_pass_header Set Cookie; } log_format access $remote_addr $remote_user [$time_local] "$request" $status $body_bytes_sent "$_referer" "$_user_agent" $_x_forwarded_for ; access_log / }
总的来说 nginx的proxy_cache和fastcgi_cache的缓存配置差不多memcache缓存在讨论memcache缓存之前 我们先了解下mysql的内存缓存吧mysql的内存缓存可以在my cnf中指定大小内存表和临时表不同 临时表也是存放内存中 临时表最大的内存需要通过tmp_table_size= M设定 当数据查过临时表的最大值设定时 自动转为磁盘表 此时因需要进行IO操作 性能会大大下降 而内存表不会 内存满了后 会提示数据满错误 例
复制代码代码如下: create table test ( id int unsigned not null auto_increment primary key state char( ) type char( ) date char( ) )engine=memory default charset=utf lishixinzhi/Article/program/PHP/201311/21248
云南北大青鸟设计培训告诉你PHP应用中常用的9大缓存技术?一、全页面静态化缓存
也就是将页面全部生成html静态页面,用户访问时直接访问的静态页面,而不会去走php服务器解析的流程 。此种方式 , 在CMS系统中比较常见,比如dedecms;

推荐阅读