List Info

Thread: code for 404 pattern (aka static cache)




code for 404 pattern (aka static cache)
country flaguser name
United Kingdom
2007-09-29 04:45:18
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  {
	
	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/$.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  {
	set fn "/b/photo/$.jpg"
	file delete $fn
}


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

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

Re: code for 404 pattern (aka static cache)
country flaguser name
United States
2007-09-29 17:00:35
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


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

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

Re: code for 404 pattern (aka static cache)
country flaguser name
United Kingdom
2007-09-30 02:02:35
On Sep 29, 2007, at 11:00 PM, Jeff Rogers wrote:

> 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

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

-john


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

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

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )