我正在编写一个当前在 2.2.22 上运行的 Apache 模块。该模块运行以新编程语言编写的脚本,并且为了优化,它缓存解析结果以供后续使用。
由于在修改文件时应删除缓存的解析,因此我存储修改时间并在每次运行时对照文件系统进行检查。
这是一些带有调试消息的代码:
if (file->is_modified (mtime)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"P* removing cached file");
files.erase(it);
}
Run Code Online (Sandbox Code Playgroud)
我在测试这个(获取页面,修改文件,再次获取)时发现,这个块永远不会到达。该文件在更改后再次解析,但不是因为此检查。在我看来,Apache 本身正在检查修改时间并释放模块中的所有内存。
解析后的文件在未修改时可以正确重用。
这是 Apache 服务器的预期行为吗,如果是,这叫什么,它在哪里记录?
检查缓存程序的函数的完整代码
shared_ptr<pstar_file> pstar_pool::get_file_handle (
request_rec *r,
wpl_io &io,
const char *filename,
int mtime
)
{
pstar_map_t::iterator it;
apr_proc_mutex_lock (mutex);
// Check if a cached program exists
it = files.find(filename);
if (it != files.end()) {
if (it->second->is_modified (mtime)) {
files.erase(it);
}
else {
apr_proc_mutex_unlock (mutex);
return it->second;
}
}
apr_proc_mutex_unlock (mutex);
shared_ptr<pstar_file> file_ptr(new pstar_file(io, …
Run Code Online (Sandbox Code Playgroud) apache-2.2 ×1