tony-landis (owner)

Revisions

gist: 33018 Download_button fork
public
Description:
Lua for Lighttpd to rewrite to a handler script if cached copy of requested file is missing
Public Clone URL: git://gist.github.com/33018.git
Embed All Files: show embed
Lua #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cache_path = "/var/www/site/tmp"
cache_code = "compile"
 
-- render and cache to the filesystem
function cache_gen()
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. "/index.php"
lighty.env["uri.query"] = "p=" .. string.gsub(lighty.env["uri.path"], "\.(htm|html)$", "")
--print ("CACHE: " .. lighty.env["uri.query"])
end
 
-- load the cached copy from the filesystem
function cache_load()
lighty.env["physical.path"] = cache_path .. lighty.env["uri.path"]
--print ("LOAD: " .. cache_path .. lighty.env["uri.path"])
end
 
-- add index file if directory listing requested
if(lighty.env["uri.path"] == "" or string.find(lighty.env["uri.path"], "/", -1)) then
lighty.env["uri.path"] = lighty.env["uri.path"] .. "index.html"
end
 
-- process htm|html file requests
if(string.find(lighty.env["uri.path"], "htm", -4)) then
exists = lighty.stat(cache_path .. lighty.env["uri.path"])
 
cache_code_passed = false
if(lighty.env["uri.query"] ) then
cache_code_passed = string.find(lighty.env["uri.query"], cache_code)
end
 
if(exists and not cache_code_passed) then
action = cache_load()
else
action = cache_gen()
end
end