nginx proxy_cache 下的文件内存索引(fcn)和文件的一些实现
来源:互联网 发布:手机变平板软件 编辑:程序博客网 时间:2024/04/28 16:29
指令:
proxy_cache_path path [levels=levels] keys_zone=name:size [inactive=time] [max_size=size] [loader_files=number] [loader_sleep=time] [loader_threshold=time];
demo:
proxy_cache_path /home/disk2/czh_autohome levels=1:2 keys_zone=czh_autohome_c2:512m inactive=1d max_size=512m;
inactive:
Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default, inactive is set to 10 minutes.
max_size:
The special “cache manager” process monitors the maximum cache size set by the max_size parameter. When this size is exceeded, it removes the least recently used data.
文件缓存节点fcn(代表proxy_cache在内存中的索引对象),在源代码中,涉及inactive的地方
一、正常请求到来时:
在方法ngx_http_file_cache_exists内部:
三、cache manager 管理缓存过期时
在方法ngx_http_file_cache_manager内部:
在方法ngx_http_file_cache_expire内部:
ngx_http_file_cache_delete(cache, q, name);
continue;
}
在 ngx_http_file_cache_delete内部
1、如果文件缓存节点存在(fcn->exists),则根据文件路径,删除文件
2、如果文件缓存节点引用计数(fcn->count)为0,则从队列中删除该节点
proxy_cache_path path [levels=levels] keys_zone=name:size [inactive=time] [max_size=size] [loader_files=number] [loader_sleep=time] [loader_threshold=time];
demo:
proxy_cache_path /home/disk2/czh_autohome levels=1:2 keys_zone=czh_autohome_c2:512m inactive=1d max_size=512m;
inactive:
Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default, inactive is set to 10 minutes.
max_size:
The special “cache manager” process monitors the maximum cache size set by the max_size parameter. When this size is exceeded, it removes the least recently used data.
文件缓存节点fcn(代表proxy_cache在内存中的索引对象),在源代码中,涉及inactive的地方
一、正常请求到来时:
在方法ngx_http_file_cache_exists内部:
//当结束时,在当前时间的基础上,增加inactive的值
done:
fcn->expire = ngx_time() + cache->inactive;
二、cache loader 加载缓存文件时
在方法ngx_http_file_cache_add内部:
//在通过遍历目录加载指定文件后,设置fcn属性,并插入队列
fcn->expire = ngx_time() +cache->inactive;
ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
三、cache manager 管理缓存过期时
在方法ngx_http_file_cache_manager内部:
//先删除过期的缓存文件
ngx_http_file_cache_expire
//如果缓存文件的总容量超过设置的max_size容量,则强制删除过期文件
if (size <cache->max_size) {
return next;
}//执行强制过期
wait = ngx_http_file_cache_forced_expire(cache);
在方法ngx_http_file_cache_expire内部:
//计算缓存文件索引是否已经过期
wait = fcn->expire - now;
if (wait > 0) {
wait = wait > 10 ? 10 : wait;
break;}
//如果该缓存文件节点已经过期,并且缓存节点的引用计数为0,则执行删除
if (fcn->count == 0) {
ngx_http_file_cache_delete(cache, q, name);
continue;
}
在 ngx_http_file_cache_delete内部
1、如果文件缓存节点存在(fcn->exists),则根据文件路径,删除文件
2、如果文件缓存节点引用计数(fcn->count)为0,则从队列中删除该节点
0 0
- nginx proxy_cache 下的文件内存索引(fcn)和文件的一些实现
- 流和文件(文件目录的一些操作)
- Nginx在Mac下的配置和文件结构讲解
- nginx中配置proxy_cache使用内存的方法
- 流和文件(文件的保存)
- nginx的403 Forbidden解决的办法(权限文件和文件不存在)
- nginx的403 Forbidden解决的办法(权限文件和文件不存在、SElinux 开启)
- Android中内存缓存和文件缓存的实现原理
- Android中内存缓存和文件缓存的实现原理
- nginx 的proxy_cache才是王道
- nginx 的proxy_cache才是王道
- Nginx的proxy_cache缓存功能
- 统计文件下包含的文件夹和文件的数目
- Linux — linux下的文件标述符和文件指针
- Linux下的文件流和文件描述符
- Lucene_demo05_内存索引和文件索引
- 使用VC实现读取指定路径下的文件,并显示所有文件的文件名和文件图标
- C#实现的列出目录下所有子目录和文件的程序(附思路)
- Python subprocess.Popen 只接受 list 不接受单个 string
- Html快速入门
- androidScanner 扫描文件
- Nginx、LVS及HAProxy负载均衡软件的优缺点详解
- Qt笔记——元对象系统
- nginx proxy_cache 下的文件内存索引(fcn)和文件的一些实现
- GCC相关资料收集
- android开发中遇到的那些问题
- 自定义字节缓冲队列
- Hdu 1016 Prime Ring Problem DFS搜索
- Android学习笔记之资源文件resource/raw和assets各自的特点。
- 7.25 IDE试用和调试
- Android中获取SD卡下的图片资源
- javaScript模块规范、AMD、CMD