-- Helper Functions function file_exists(path) local attr = lighty.stat(path) if (attr and attr["is_file"]) then return true else return false end end function removePrefix(str, prefix) return str:sub(1,#prefix+1) == prefix .. "/" and str:sub(#prefix+2) end function string.starts(x,y) return string.sub(x,1,string.len(y)) == y end -- Set for subdirectory drupal installs local prefix = '' -- If this is not an existing file if (not file_exists(lighty.env["physical.path"])) then -- Set Drupal Expires Headers lighty.header["Expires"] = "Sun, 19 Nov 1978 05:00:00 GMT" lighty.header["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" -- Set local variables local FINAL_PATH = "empty" local request_uri = removePrefix(lighty.env["uri.path"], prefix) -- none should be set to '/' local request_query = lighty.env["uri.query"] or "" -- Set 1st filter (anon+GET) to qualify boost caching local SERVE_CACHED_FLAG = (string.find((lighty.request["Cookie"] or "NOCOOKIE"), "DRUPAL_UID") == nil) and (lighty.env["request.method"] == "GET") -- Set 2nd filter to qualify boosted paths local RESTRICTED_PATHS = (string.starts(request_uri,"/user")) or (string.starts(request_uri,"/cache")) or (string.starts(request_uri,"/admin")) or (string.starts(request_uri,"/openid")) or (string.starts(request_uri,"/node/add")) -- If qualifies for boost caching if (SERVE_CACHED_FLAG == true and RESTRICTED_PATHS == false) then -- Build filename based on URL for cached pages local boost_path_normal = lighty.env["physical.doc-root"] .. "/cache/normal/" .. lighty.request["Host"] .. request_uri .. "_" .. request_query -- Build filename based on URL for cached css/js local boost_path_perm = lighty.env["physical.doc-root"] .. "/cache/perm/" .. lighty.request["Host"] .. request_uri .. "_" -- Set Final Path & Content-Type if this file exists. if (file_exists(boost_path_perm .. ".css")) then FINAL_PATH = boost_path_perm .. ".css" lighty.header["Content-Type"] = "text/css" end if (file_exists(boost_path_perm .. ".js")) then FINAL_PATH = boost_path_perm .. ".js" lighty.header["Content-Type"] = "text/javascript" end if (file_exists(boost_path_normal .. ".html")) then FINAL_PATH = boost_path_normal .. ".html" lighty.header["Content-Type"] = "text/html" end if (file_exists(boost_path_normal .. ".xml")) then FINAL_PATH = boost_path_normal .. ".xml" lighty.header["Content-Type"] = "text/xml" end if (file_exists(boost_path_normal .. ".json")) then FINAL_PATH = boost_path_normal .. ".json" lighty.header["Content-Type"] = "text/javascript" end end -- URL not in boost cache, send it to drupal if (FINAL_PATH == "empty") then if request_uri then lighty.env["uri.path"] = prefix .. "/index.php" lighty.env["uri.query"] = request_query .. (request_query ~= "" and "&" or "") .. "q=" .. request_uri lighty.env["physical.rel-path"] = lighty.env["uri.path"] lighty.env["request.orig-uri"] = lighty.env["request.uri"] FINAL_PATH = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"] end end -- Do it lighty.env["physical.path"] = FINAL_PATH end