Class ::xo::db::CrCache::Item

::xo::db::CrCache::Item[i] create ...

Class Relations

  • class: ::xotcl::Class[i]
  • superclass: ::xotcl::Object[i]
  • instmixinof: ::xo::db::CrItem[i]
::xotcl::Class create ::xo::db::CrCache::Item \
     -superclass ::xotcl::Object

Methods (to be applied on instances)

  • delete (scripted)

    #
    # Not all cr_items are cached. Some of the bulk creation commands
    # create autonamed items, which have non-numeric object names. So
    # the flush on these will fail anyhow, since these were never
    # added to the cache.
    #
    if {[:is_cached_object]} {
      ::xo::xotcl_object_cache flush [string trimleft [self] :]
    }
    xo::xotcl_object_type_cache flush -partition_key ${:parent_id} ${:parent_id}-${:name}
    acs::per_request_cache flush -pattern xotcl-core.lookup-${:parent_id}-${:name}
    next
  • flush_from_cache_and_refresh (scripted)

    # cache only names with IDs
    set obj [self]
    set canonical_name ::[$obj item_id]
    if {[$obj is_cached_object]} {
      ::xo::xotcl_object_cache flush [string trimleft $obj :]
    }
    if {$obj eq $canonical_name} {
      #:log "--CACHE saving $obj in cache"
      #
      # The object name is equal to the item_id; we assume, this is a
      # fully loaded object, containing all relevant instance
      # variables. We can restore it. After the flash
      #
      # We do not want to cache per object mixins for the
      # time being (some classes might be volatile). So save
      # mixin-list, cache and restore them later for the current
      # session.
      set mixins [$obj info mixin]
      $obj mixin [list]
      set npv [$obj remove_non_persistent_vars]
      ::xo::xotcl_object_cache set [string trimleft $obj :] [$obj serialize]
      $obj set_non_persistent_vars $npv
      $obj mixin $mixins
    } else {
      #
      # In any case, flush the canonical name.
      #
      ::xo::xotcl_object_cache flush [string trimleft $canonical_name :]
    }
    # To be on he safe side, delete the revision as well from the
    # cache, if possible.
    if {[$obj exists revision_id]} {
      set revision_id [$obj revision_id]
      set revision_obj ::$revision_id
      if {$obj ne $revision_obj} {
        ::xo::xotcl_object_cache flush $revision_id
      }
    }
    acs::per_request_cache flush -pattern xotcl-core.lookup-${:parent_id}-${:name}
  • remove_non_persistent_vars (scripted)

    #
    # Do not save __db__artefacts in the cache.
    #
    foreach x [info vars :__db_*] {
      unset :$x
    }
    #
    # Remove vars and arrays matching the class-specific specified
    # non_cached_instance_var_patterns and treat these as variables,
    # which are not stored in the cache, but which are kept in the
    # instance variables. These variables are removed before caching
    # and restored afterwards.
    #
    set arrays {}
    set scalars {}
    set non_cached_vars {}
    foreach pattern [[:info class] non_cached_instance_var_patterns] {
      lappend non_cached_vars {*}[:info vars $pattern]
    }
    
    #ns_log notice "pattern [[:info class] non_cached_instance_var_patterns], non_cached_vars <$non_cached_vars>"
    foreach x $non_cached_vars {
      if {[array exists :$x]} {
        lappend arrays $x [array get :$x]
        array unset :$x
      } {
        lappend scalars $x [set :$x]
        unset -nocomplain :$x
      }
    }
    return [list $arrays $scalars]
  • rename (scripted)

    ::xo::xotcl_object_type_cache flush -partition_key ${:parent_id} ${:parent_id}-$old_name
    acs::per_request_cache flush -pattern xotcl-core.lookup-${:parent_id}-$old_name
    next
  • save (scripted)

    #
    # We perform next before the cache update, since when update
    # fails, we do not want to populate wrong content in the cache.
    #
    set r [next]
    :flush_from_cache_and_refresh
    return $r
  • save_new (scripted)

    set item_id [next]
    #ns_log notice "===== save_new acs::per_request_cache flush -pattern xotcl-core.lookup-${:parent_id}-${:name}"
    acs::per_request_cache flush -pattern xotcl-core.lookup-${:parent_id}-${:name}
    return $item_id
  • set_non_persistent_vars (scripted)

    lassign $vars arrays scalars
    foreach {var value} $arrays {:array set $var $value}
    :mset $scalars
  • update_attribute_from_slot (scripted)

    set r [next]
    :flush_from_cache_and_refresh
    return $r