]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
Introduced (cached) method ifNodeDataIsFound()
[hub.git] / application / hub / main / database / wrapper / node / class_NodeDistributedHashTableDatabaseWrapper.php
index 40f96ace88ee29fbd224a06118e270bebdbee169..70b5a58a380bb2d44621c54d5e6997c352b96db8 100644 (file)
@@ -63,24 +63,27 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
         * @return      $isRegistered   Whether *this* node is registered in the DHT
         */
        public function isLocalNodeRegistered () {
-               // Get a search criteria instance
-               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               // Is there cache?
+               if (!isset($GLOBALS[__METHOD__])) {
+                       // Get a search criteria instance
+                       $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
-               // Get node instance
-               $nodeInstance = Registry::getRegistry()->getInstance('node');
+                       // Get node instance
+                       $nodeInstance = Registry::getRegistry()->getInstance('node');
 
-               // Add ip:port as criteria
-               $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort());
-               $searchInstance->setLimit(1);
+                       // Add ip:port as criteria
+                       $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort());
+                       $searchInstance->setLimit(1);
 
-               // Query database and get a result instance back
-               $resultInstance = $this->doSelectByCriteria($searchInstance);
+                       // Query database and get a result instance back
+                       $resultInstance = $this->doSelectByCriteria($searchInstance);
 
-               // Is there an entry?
-               $isRegistered = $resultInstance->next();
+                       // Cache result of if there is an entry, next() will tell us if the next entry is valid
+                       $GLOBALS[__METHOD__] = $resultInstance->next();
+               } // END - if
 
                // Return result
-               return $isRegistered;
+               return $GLOBALS[__METHOD__];
        }
 
        /**