improve perfomance by avoiding double cache hit
authorLars Kneschke <l.kneschke@metaways.de>
Mon, 29 Dec 2014 12:11:58 +0000 (13:11 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 29 Dec 2014 12:40:08 +0000 (13:40 +0100)
Change-Id: Ib5366851ed72f6ba5857f5a186e29f256cc340ec
Reviewed-on: http://gerrit.tine20.com/customers/1488
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Server/Json.php

index 0ad262a..5d07aa1 100644 (file)
@@ -127,12 +127,12 @@ class Tinebase_Server_Json extends Tinebase_Server_Abstract implements Tinebase_
         // setup cache if available
         if (is_array($classes) && Tinebase_Core::getCache()) {
             $masterFiles = array();
-        
+            
             $dirname = dirname(__FILE__) . '/../../';
             foreach ($classes as $class => $namespace) {
                 $masterFiles[] = $dirname . str_replace('_', '/', $class) . '.php';
             }
-        
+            
             try {
                 $cache = new Zend_Cache_Frontend_File(array(
                     'master_files'              => $masterFiles,
@@ -145,19 +145,18 @@ class Tinebase_Server_Json extends Tinebase_Server_Abstract implements Tinebase_
                 ));
                 $cache->setBackend(Tinebase_Core::getCache()->getBackend());
                 $cacheId = '_handle_' . sha1(Zend_Json_Encoder::encode($classes));
+                
+                $server = $cache->load($cacheId);
+                if ($server instanceof Zend_Json_Server) {
+                    return $server;
+                }
+                
             } catch (Zend_Cache_Exception $zce) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
                     . " Failed to create cache. Exception: \n". $zce);
             }
         }
         
-        if (isset($cache) && $cache->test($cacheId)) {
-            $server = $cache->load($cacheId);
-            if ($server instanceof Zend_Json_Server) {
-                return $server;
-            }
-        }
-        
         $server = new Zend_Json_Server();
         $server->setAutoEmitResponse(false);
         $server->setAutoHandleExceptions(false);