1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-07 04:02:58 +03:00

Add LuaCodeCache directive for controlling in-memory caching.

This might need some tweaking on the hash key generation for the mtime lookups, ideas are welcome.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1366890 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Gruno
2012-07-29 19:07:38 +00:00
parent 6722d47519
commit f9b07d1b34
4 changed files with 81 additions and 2 deletions

View File

@@ -341,7 +341,7 @@ AP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
ap_lua_vm_spec *spec)
{
lua_State *L = NULL;
int tryCache = 0;
if (apr_pool_userdata_get((void **)&L, spec->file,
lifecycle_pool) == APR_SUCCESS) {
@@ -360,6 +360,43 @@ AP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
}
}
/*}*/
if (spec->codecache == AP_LUA_CACHE_FOREVER || (spec->bytecode && spec->bytecode_len > 0)) {
tryCache = 1;
}
else if (spec->codecache == AP_LUA_CACHE_STAT) {
apr_time_t modified;
char* mkey = apr_psprintf(lifecycle_pool, "ap_lua_modified:%s", spec->file);
if (apr_pool_userdata_get((void **)&modified, mkey,
lifecycle_pool) == APR_SUCCESS) {
apr_finfo_t lua_finfo;
apr_stat(&lua_finfo, spec->file, APR_FINFO_MTIME, lifecycle_pool);
/* On first visit, modified will be zero, but that's fine - The file is
loaded in the vm_construct function.
*/
if (modified == lua_finfo.mtime || modified == 0) tryCache = 1;
modified = lua_finfo.mtime;
}
else {
tryCache = 1;
}
apr_pool_userdata_set((void*) modified, mkey, NULL, lifecycle_pool);
}
if (tryCache == 0) {
int rc;
ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01481)
"(re)loading lua file %s", spec->file);
rc = luaL_loadfile(L, spec->file);
if (rc != 0) {
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, lifecycle_pool, APLOGNO(01482)
"Error loading %s: %s", spec->file,
rc == LUA_ERRMEM ? "memory allocation error"
: lua_tostring(L, 0));
return 0;
}
lua_pcall(L, 0, LUA_MULTRET, 0);
}
return L;
}