AOL Webserver - code for 404 pattern (aka static cache)

This is Interesting: Free IT Magazines  
Home > Archive > AOL Webserver > September 2007 > code for 404 pattern (aka static cache)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author code for 404 pattern (aka static cache)
John Buckman

2007-09-29, 7:11 am

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
}


Jeff Rogers

2007-09-29, 7:11 pm

John Buckman wrote:
> 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.


I've taken the liberty of adding this to the wiki, on the "Cookbook"
page: http://panoptic.com/wiki/aolserver/AOLserver_Cookbook

-J


John Buckman

2007-09-30, 7:11 am

On Sep 29, 2007, at 11:00 PM, Jeff Rogers wrote:

> John Buckman wrote:
>
> I've taken the liberty of adding this to the wiki, on the
> "Cookbook" page: http://panoptic.com/wiki/aolserver/AOLserver_Cookbook


Thanks for reminding us of this wiki page. I'll endeavor to put my
"bits" in there in the future.

-john


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com