%3 ::nx::Object ::nx::Object ::acs::SiteNodeUrlspaceCache ::acs::SiteNodeUrlspaceCache flush_cache get_node_id ::acs::SiteNodeUrlspaceCache->::nx::Object

Class ::acs::SiteNodeUrlspaceCache

::acs::SiteNodeUrlspaceCache[i] create ...

Cache site-node information via ns_urlspace. We can use the URL trie, which supports tree match operations, for tree information. This means that for example for .vuh handlers it is not necessary to cache the full url for obtaining the site-node, like it was until now: 3839 id-/storage/view/installers/windows-installer/installer.htm 3839 id-/storage/view/aolserver/install.tgz 3839 id-/storage/view/tutorial/OpenACS_Tutorial.htm 3839 id-/storage/view/openacs-dotlrn-conference-2007-spring/Methodology_ALPE.pdf 3839 id-/storage/view/xowiki-resources/Assessment.jpg 3839 id-/storage/view/tutorial-page-map.png ... Providing a single entry like ns_urlspace set -key sitenode /storage/* 3839 is sufficient for replacing all entries above.
Defined in packages/acs-tcl/tcl/site-nodes-procs.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
  • mixinof: ::acs::site_node[i]
::nx::Class create ::acs::SiteNodeUrlspaceCache \
     -superclass ::nx::Object

Methods (to be applied on instances)

  • flush_cache (scripted, public)

     <instance of acs::SiteNodeUrlspaceCache[i]> flush_cache \
        -node_id node_id  [ -with_subtree on|off ] [ -url url ]

    Cleanup in the urlspace tree: Clear always the full subtree via "-recurse" (maybe not always necessary).

    Switches:
    -node_id (required)
    -with_subtree (optional, boolean, defaults to "true")
    -url (optional)

    Testcases:
    No testcase defined.
    ::acs::clusterwide ns_urlspace unset -id $::acs::siteNodesID -recurse -key sitenode $url
    next
  • get_node_id (scripted, public)

     <instance of acs::SiteNodeUrlspaceCache[i]> get_node_id -url url 

    Get node_id for the provided URL. We have to determine the partial URL for determining the site node.

    Switches:
    -url (required)
    Returns:
    node_id (integer)

    Testcases:
    No testcase defined.
    #
    # This is the main interface of the
    # SiteNodeUrlspaceCache to provide a first-level
    # cache.
    #
    
    # Try per-request caching
    #
    if {[dict exists ${:static_site_nodes} $url]} {
        set key :node_id($url)
    } else {
        set key ::__node_id($url)
    }
    if {[info exists $key]} {
        #ns_log notice "==== returning cached value [set $key]"
        return [set $key]
    }
    
    #
    # Try to get value from urlspace
    #
    set ID [ns_urlspace get -id $::acs::siteNodesID -key sitenode $url]
    if {$ID eq ""} {
        #
        # Get value the classical way, caching potentially
        # the full url path in the site_nodes_id_cache.
        #
        set ID [next]
        #ns_log notice "--- get_node_id from site_nodes_id_cache <$url> -> <$ID>"
        if {$ID ne ""} {
            #
            # We got a valid ID. If we would add blindly a
            # node_id for the returned URL (e.g. for "/*")
            # and some other subnode is not jet resolved,
            # we would obtain later the node_id of the
            # parent_node although there is a subnode.
            #
            # We could address this by e.g. pre-caching
            # all "inner nodes" or similar, but this
            # requires a deeper analysis of larger sites.
            #
            # In earlier versions, we had here
            #   ... {[site_node::get_children -node_id $ID] eq ""} ...
            # but on site_node trees with huge number of entries,
            # this is a waste.
            #
            if {![:has_children -node_id $ID]} {
                #
                # We are on a leaf-node of the site node
                # tree. Get the shortened url and save it
                # in the urlspace.
                #
                set short_url [site_node::get_url -node_id $ID]
                set cmd [list ns_urlspace set -id $::acs::siteNodesID -key sitenode $short_url$ID]
                #ns_log notice "--- get_node_id save in urlspace <$cmd> -> <$ID>"
                {*}$cmd
                #ns_log notice "---\n[join [ns_urlspace list -id $::acs::siteNodesID] \n]"
            }
            return [set $key $ID]
        }
    }
    return $ID