im_memoize_list

one of the documented procedures in this installation of the ACS
Usage:
im_memoize_list   sql_query   { force "0" }   { also_memoize_as "" }
What it does:
Allows you to memoize database queries without having to grab a db handle first. If the query you specified is not in the cache, this proc grabs a db handle, and memoizes a list, separated by $divider inside the cache, of the results. Your calling proc can then process this list as normally.
Defined in: /web/philip/tcl/intranet-defs.tcl

Source code:


    ns_share im_memoized_lists

    set str ""
    set divider "\253"

    if { !$force && [info exists im_memoized_lists($sql_query)] } {
	set str $im_memoized_lists($sql_query)
    } else {
	# ns_log Notice "Going to db to memoize $sql_query"
	set db [ns_db gethandle subquery]
	set selection [ns_db select $db $sql_query]
	while { [ns_db getrow $db $selection] } {
	    set i 0
	    set limit [ns_set size $selection]
	    while {$i<$limit} {
		if { ![empty_string_p $str] } {
		    append str $divider
		}
		append str [ns_set value $selection $i]
		incr i
	    }
	}
	ns_db releasehandle $db
	set im_memoized_lists($sql_query) $str
    }
    if { ![empty_string_p $also_memoize_as] } {
	set im_memoized_lists($also_memoize_as) $str
    }
    return [split $str $divider]


philg@mit.edu