Bas Scheffers was kind to share his 404-pattern code with me (ie, a custom 404 handler to enable static caching of frequently requested files), which I used to write my own.

It's not rocket science, but since I asked the question, I thought I'd share my code, in case anyone else finds it helpful.

-john

from config.tcl:
ns_section "ns/server/$server1/redirects"
ns_param   404           /404.adp

$ cat 404.adp
<% handle_404 %>


proc handle_404 {} {
        set myurl [myurl]
        set parts [split $myurl /]
        set root [lindex $parts 1]

        if {$root == "photo"} {
                return [404_photo $parts]
        } else {
                ns_returnredirect "[myhost]/"
                return
        }
        
}

proc 404_photo {parts} {
        
        set userid [file rootname [lindex $parts 2]]
        set d [user_photo_data $userid]
        if {$d == ""} {
                set fn "/b/photo/unknown.jpg"
        } else {
                set fn "/b/photo/${userid}.jpg"
                write_binary_file $fn $d
        }
        ns_returnfile 200 "image/jpeg" $fn
}

proc myurl {} {
        return [lindex [split [ns_conn request]] 1]     
}

proc photo_cache_dirty {userid} {
        set fn "/b/photo/${userid}.jpg"
        file delete $fn
}


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to