I am writing on an Apache module which currently runs on 2.2.22. The module runs scripts written in a new programming language, and for optimization, it caches the results of the parsing for successive uses.
Since the cached parsing should be deleted when the file is modified, I store the modification time and check it against the filesystem on each run.
This is some of the code with a debug message:
if (file->is_modified (mtime)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"P* removing cached file");
files.erase(it);
}
What I discovered when testing this (get a page, modify the file, get it again), is that this block never is reached. The file is parsed again after it's changed, but not because of this check. It looks to me like Apache itself is checking the modification time and is freeing all the memory in the module.
The parsed files are re-used correctly when left unmodified.
Is this intended behavior of the Apache server, and if so, what is this called and where is it documented?
Full code for the function which checks for cached programs
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, filename, mtime));
apr_proc_mutex_lock (mutex);
files.insert(std::pair<string,shared_ptr<pstar_file>>(filename, file_ptr));
apr_proc_mutex_unlock (mutex);
return file_ptr;
}
Full code for the whole module on Github (multiple files): https://github.com/atlesn/P-star/blob/master/src/apache2/pstar_pool.cpp