Changeset 10144

Show
Ignore:
Timestamp:
07/14/10 16:44:59 (3 years ago)
Author:
p_lindheimer
Message:

proposed caching of astdb during open astman session, must be enabled to take advantage, re #4435

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/common/php-asmanager.php

    r10143 r10144  
    113113  */ 
    114114  var $event_handlers; 
     115 
     116  var $useCaching = false; 
     117  var $memAstDB = null; 
    115118   
    116119  /** 
     
    137140    if(!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username'] = 'phpagi'; 
    138141    if(!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret'] = 'phpagi'; 
    139   } 
    140    
     142 
     143    if(isset($this->config['asmanager']['cachemode'])) $this->useCaching = $this->config['asmanager']['cachemode']; 
     144  } 
     145 
     146  function LoadAstDB(){         
     147    if ($this->memAstDB != null) unset($this->memAstDB); 
     148    $this->memAstDB = $this->database_show(); 
     149  } 
     150 
    141151  /** 
    142152  * Send a request 
     
    735745   */ 
    736746  function database_show($family='') { 
     747    if ($this->useCaching && $this->memAstDB != null) { 
     748      if ($family == '') { 
     749        return $this->memAstDB; 
     750      } else { 
     751        $key = '/'.$family; 
     752        if (isset($this->memAstDB[$key])) { 
     753          return array($key => $this->memAstDB[$key]); 
     754        } else { 
     755          $key .= '/'; 
     756          $len = strlen($key); 
     757          $fam_arr = array(); 
     758          foreach ($this->memAstDB as $this_key => $value) { 
     759            if (substr($this_key,0,$len) ==  $key) { 
     760              $fam_arr[$this_key] = $value; 
     761            } 
     762          } 
     763          return $fam_arr; 
     764        } 
     765      } 
     766    } 
    737767    $r = $this->command("database show $family"); 
    738768     
     
    762792    $value = (trim($value) == '')?'"'.$value.'"':$value; 
    763793    $r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." ".$value); 
     794    if (!empty($this->memAstDB)){ 
     795      $keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key); 
     796      $this->memAstDB[$keyUsed] = $value; 
     797    } 
    764798    return (bool)strstr($r["data"], "success"); 
    765799  } 
     
    770804   * @return mixed Value of the key, or false if error 
    771805   */ 
     806   /* 
    772807  function database_get($family, $key) { 
    773808    $r = $this->command("database get ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); 
     
    779814    } 
    780815  } 
     816  */ 
     817  function database_get($family, $key) { 
     818    if ($this->useCaching) { 
     819      if ($this->memAstDB == null) { 
     820        $this->LoadAstDB(); 
     821      } 
     822      $keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key); 
     823      if (array_key_exists($keyUsed,$this->memAstDB)){             
     824        return $this->memAstDB[$keyUsed]; 
     825      } 
     826    } else { 
     827      $r = $this->command("database get ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); 
     828      $data = strpos($r["data"],"Value:"); 
     829      if ($data !== false) { 
     830        return trim(substr($r["data"],6+$data)); 
     831      } 
     832    } 
     833    return false; 
     834  } 
     835 
    781836   
    782837  /** Delete an entry from the asterisk database 
     
    786841   */ 
    787842  function database_del($family, $key) { 
     843    if (!empty($this->memAstDB)){ 
     844      $keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key); 
     845      unset($this->memAstDB[$keyUsed]); 
     846    } 
    788847    $r = $this->command("database del ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); 
    789848    return (bool)strstr($r["data"], "removed"); 
     
    795854   */ 
    796855  function database_deltree($family) { 
     856    if (!empty($this->memAstDB)){ 
     857      $keyUsed="/".str_replace(" ","/",$family); 
     858      unset($this->memAstDB[$keyUsed]); 
     859    } 
    797860    $r = $this->command("database deltree ".str_replace(" ","/",$family)); 
    798861    return (bool)strstr($r["data"], "removed");