Example #1
0
 /**
  * Invalidates all cache objects related to the GUID specified. This function is aware for
  * NAP / Metadata caches. It will invalidate the node/leaf record pair upon each invalidation.
  *
  * This function only works within the current context, because it looks on the invalidated
  * GUID to handle the invalidation correctly.
  *
  * <b>Note, for GUIDs which cannot be resolved by NAP:</b>
  *
  * It should be safe to just skip this case, because if the object to be invalidated
  * cannot be found, it is not cached anyway (deleted items could be resolved using
  * the resolve_guid code which uses the cache, so they would still be found).
  * Special cases, where objects not available through NAP are updated have to be handled
  * by the component anyway.
  *
  * This way, leaf deletions should be safe in all cases (if they are cached, they can
  * still be resolved, if not, they aren't in the cache anyway). The Datamanager tries
  * to catch leaf creations using its internal creation mode flag, invalidating the
  * current content topic instead of the actual object in this case. Note, that this happens
  * directly after object creation, not during the regular safe cycle.
  *
  * See the automatic index invalidation code of the Datamanager for additional details.
  *
  * @todo Find a way to propagate leaf additions/deletions to a topic which must be invalidated in all
  * places necessary, or MIDCOM_NAV_LEAVES will be broken.
  *
  * @param string $guid The GUID to invalidate.
  */
 function invalidate($guid)
 {
     $nav = new midcom_helper_nav();
     $napobject = $nav->resolve_guid($guid);
     if ($napobject === false) {
         // Ignoring this should be safe, see the method documentation for details.
         debug_add("We failed to resolve the GUID {$guid} with NAP, apparently it is not cached or no valid NAP node, skipping it therefore.", MIDCOM_LOG_INFO);
         return;
     }
     if ($napobject[MIDCOM_NAV_TYPE] == 'leaf') {
         $cached_node_id = $napobject[MIDCOM_NAV_NODEID];
         // Get parent from DB and compare to catch moves
         if ($parent = $napobject[MIDCOM_NAV_OBJECT]->get_parent()) {
             $parent_entry_from_object = $nav->resolve_guid($parent->guid);
             if ($parent_entry_from_object && $parent_entry_from_object[MIDCOM_NAV_ID] != $cached_node_id) {
                 $this->_cache->remove($this->_prefix . '-' . $parent_entry_from_object[MIDCOM_NAV_ID] . '-leaves');
             }
         }
         if (!empty($napobject[MIDCOM_NAV_GUID])) {
             $this->_cache->remove($this->_prefix . '-' . $napobject[MIDCOM_NAV_GUID]);
         }
     } else {
         $cached_node_id = $napobject[MIDCOM_NAV_ID];
         //Invalidate subnode cache for the (cached) parent
         $parent_id = $napobject[MIDCOM_NAV_NODEID];
         $parent_entry = $this->_cache->get("{$this->_prefix}-{$parent_id}");
         if ($parent_entry && array_key_exists(MIDCOM_NAV_SUBNODES, $parent_entry)) {
             unset($parent_entry[MIDCOM_NAV_SUBNODES]);
             $this->_cache->put("{$this->_prefix}-{$parent_id}", $parent_entry);
         }
         //Cross-check parent value from object to detect topic moves
         if ($parent = $napobject[MIDCOM_NAV_OBJECT]->get_parent()) {
             $parent_entry_from_object = $nav->resolve_guid($parent->guid);
             if (!empty($parent_entry_from_object[MIDCOM_NAV_ID]) && !empty($parent_entry[MIDCOM_NAV_ID]) && $parent_entry_from_object[MIDCOM_NAV_ID] != $parent_entry[MIDCOM_NAV_ID]) {
                 unset($parent_entry_from_object[MIDCOM_NAV_SUBNODES]);
                 $this->_cache->put("{$this->_prefix}-{$parent_entry_from_object[MIDCOM_NAV_ID]}", $parent_entry_from_object);
             }
         }
     }
     $leaves_key = "{$cached_node_id}-leaves";
     $this->_cache->remove("{$this->_prefix}-{$cached_node_id}");
     $this->_cache->remove($this->_prefix . '-' . $napobject[MIDCOM_NAV_GUID]);
     $this->_cache->remove("{$this->_prefix}-{$leaves_key}");
 }
Example #2
0
 /**
  * Looks for list of content and request identifiers paired with the given guid
  * and removes all of those from the caches.
  */
 function invalidate($guid)
 {
     $this->_meta_cache->open();
     if (!$this->_meta_cache->exists($guid)) {
         debug_add("No entry for {$guid} in meta cache, ignoring invalidation request.");
         return;
     }
     $guidmap = $this->_meta_cache->get($guid);
     $this->_data_cache->open();
     foreach ($guidmap as $content_id) {
         if ($this->_meta_cache->exists($content_id)) {
             $this->_meta_cache->remove($content_id);
         }
         if ($this->_data_cache->exists($content_id)) {
             $this->_data_cache->remove($content_id);
         }
     }
 }