[AOLSERVER] cache function for adp pages output

3 views
Skip to first unread message

Alexey Pechnikov

unread,
Sep 3, 2009, 5:04:38 AM9/3/09
to AOLS...@listserv.aol.com
Hello!

I did write hook function for caching result of adp pages output (recursive calls is possible).
But may be exists better way for this? Is there some internal mechanism?

As example:
=======================
rename ::html::menu ::html::menu_orig
proc ::html::menu {current} {
with-adp-cache mainmenu,$current [list ::html::menu_orig $current]
}

=======================
proc with-adp-cache {key script} {
if {[info procs ns_adp_puts] ne {}} {
uplevel 1 $script
return
}
if {[nsv_exists ns_adp_cache $key] == 1} {
ns_adp_puts [nsv_get ns_adp_cache $key]
return
}
set result [with-adp-return $script]
if {[nsv_exists ns_adp_cache $key] == 0} {
nsv_set ns_adp_cache $key $result
}
ns_adp_puts $result
}

proc with-adp-return {script} {
if {[info commands ns_adp_puts_orig] eq {}} {
rename ns_adp_puts ns_adp_puts_orig
rename _ns_adp_puts ns_adp_puts
}
uplevel 1 $script
if {[info procs ns_adp_puts] ne {}} {
rename ns_adp_puts _ns_adp_puts
rename ns_adp_puts_orig ns_adp_puts
}
set _ns_adp_buffer $::_ns_adp_buffer
unset ::_ns_adp_buffer
return $_ns_adp_buffer
}

proc _ns_adp_puts {args} {
global _ns_adp_buffer
if {[llength $args] == 1} {
append _ns_adp_buffer [lindex $args 0]\n
} elseif {[llength $args] == 2 && [lindex $args 0] eq {-nonewline}} {
append _ns_adp_buffer [lindex $args 1]
} else {
return -code error "Unknown params to ns_adp_puts hook function: [info level 0]"
}
}
=======================

P.S. Code comments is on russian lang and I remove it. Function ns_adp_append is not used by me.

Best regards, Alexey Pechnikov.
http://pechnikov.tel/


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

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

Reply all
Reply to author
Forward
0 new messages