當前位置: 首頁>>代碼示例>>PHP>>正文


PHP xPDO::fromCache方法代碼示例

本文整理匯總了PHP中xPDO::fromCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP xPDO::fromCache方法的具體用法?PHP xPDO::fromCache怎麽用?PHP xPDO::fromCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xPDO的用法示例。


在下文中一共展示了xPDO::fromCache方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadCollection

 /**
  * Custom collection loader that forces access policy checking.
  *
  * {@inheritdoc}
  */
 public static function loadCollection(xPDO &$xpdo, $className, $criteria = null, $cacheFlag = true)
 {
     $objCollection = array();
     if (!($className = $xpdo->loadClass($className))) {
         return $objCollection;
     }
     $rows = false;
     $fromCache = false;
     $collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
     if (!is_object($criteria)) {
         $criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
     }
     if (is_object($criteria)) {
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
             $rows = $xpdo->fromCache($criteria, $className);
             $fromCache = is_array($rows) && !empty($rows);
         }
         if (!$fromCache) {
             $rows = xPDOObject::_loadRows($xpdo, $className, $criteria);
         }
         $cacheRows = array();
         if (is_array($rows)) {
             foreach ($rows as $row) {
                 if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) {
                     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) {
                         $cacheRows[] = $row;
                     }
                 }
             }
         } elseif (is_object($rows)) {
             while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
                 if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) {
                     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) {
                         $cacheRows[] = $row;
                     }
                 }
             }
         }
         if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($cacheRows)) {
             $xpdo->toCache($criteria, $cacheRows, $cacheFlag);
         }
     } else {
         $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'modAccessibleObject::loadCollection() - No valid statement could be found in or generated from the given criteria.');
     }
     return $objCollection;
 }
開發者ID:JoeBlow,項目名稱:revolution,代碼行數:51,代碼來源:modaccessibleobject.class.php

示例2: loadCollectionGraph

 /**
  * Load a collection of xPDOObject instances and a graph of related objects.
  *
  * @static
  * @param xPDO &$xpdo A valid xPDO instance.
  * @param string $className Name of the class.
  * @param string|array $graph A related object graph in array or JSON
  * format, e.g. array('relationAlias'=>array('subRelationAlias'=>array()))
  * or {"relationAlias":{"subRelationAlias":{}}}.  Note that the empty arrays
  * are necessary in order for the relation to be recognized.
  * @param mixed $criteria A valid primary key, criteria array, or xPDOCriteria instance.
  * @param boolean|integer $cacheFlag Indicates if the objects should be
  * cached and optionally, by specifying an integer value, for how many
  * seconds.
  * @return array An array of xPDOObject instances or an empty array if no instances are loaded.
  */
 public static function loadCollectionGraph(xPDO &$xpdo, $className, $graph, $criteria, $cacheFlag)
 {
     $objCollection = array();
     if ($query = $xpdo->newQuery($className, $criteria, $cacheFlag)) {
         $query = $xpdo->addDerivativeCriteria($className, $query);
         $query->bindGraph($graph);
         $rows = array();
         $fromCache = false;
         $collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
             $rows = $xpdo->fromCache($query);
             $fromCache = !empty($rows);
         }
         if (!$fromCache) {
             if ($query->prepare()) {
                 $tstart = microtime(true);
                 if ($query->stmt->execute()) {
                     $xpdo->queryTime += microtime(true) - $tstart;
                     $xpdo->executedQueries++;
                     $objCollection = $query->hydrateGraph($query->stmt, $cacheFlag);
                 } else {
                     $xpdo->queryTime += microtime(true) - $tstart;
                     $xpdo->executedQueries++;
                     $xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error {$query->stmt->errorCode()} executing query: {$query->sql} - " . print_r($query->stmt->errorInfo(), true));
                 }
             } else {
                 $xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error {$xpdo->errorCode()} preparing statement: {$query->sql} - " . print_r($xpdo->errorInfo(), true));
             }
         } elseif (!empty($rows)) {
             $objCollection = $query->hydrateGraph($rows, $cacheFlag);
         }
     }
     return $objCollection;
 }
開發者ID:e-gob,項目名稱:apps.gob.cl,代碼行數:50,代碼來源:xpdoobject.class.php

示例3: loadCollection

 /**
  * Custom collection loader that forces access policy checking.
  *
  * {@inheritdoc}
  */
 public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
     $objCollection= array ();
     $fromCache = false;
     if (!$className= $xpdo->loadClass($className)) return $objCollection;
     $rows= false;
     $fromCache= false;
     $collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
     if (!is_object($criteria)) {
         $criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag);
     }
     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
         $rows= $xpdo->fromCache($criteria);
         $fromCache = (is_array($rows) && !empty($rows));
     }
     if (!$fromCache && is_object($criteria)) {
         $rows= xPDOObject :: _loadRows($xpdo, $className, $criteria);
     }
     if (is_array ($rows)) {
         foreach ($rows as $row) {
             modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
         }
     } elseif (is_object($rows)) {
         $cacheRows = array();
         while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
             modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
             if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $cacheRows[] = $row;
         }
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $rows =& $cacheRows;
     }
     if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($rows)) {
         $xpdo->toCache($criteria, $rows, $cacheFlag);
     }
     return $objCollection;
 }
開發者ID:raf3600,項目名稱:revolution,代碼行數:39,代碼來源:modaccessibleobject.class.php

示例4: loadCollectionGraph

 /**
  * Load a collection of xPDOObject instances and a graph of related objects.
  *
  * @static
  * @param xPDO &$xpdo A valid xPDO instance.
  * @param string $className Name of the class.
  * @param string|array $graph A related object graph in array or JSON
  * format, e.g. array('relationAlias'=>array('subRelationAlias'=>array()))
  * or {"relationAlias":{"subRelationAlias":{}}}.  Note that the empty arrays
  * are necessary in order for the relation to be recognized.
  * @param mixed $criteria A valid primary key, criteria array, or xPDOCriteria instance.
  * @param boolean|integer $cacheFlag Indicates if the objects should be
  * cached and optionally, by specifying an integer value, for how many
  * seconds.
  * @return array An array of xPDOObject instances or an empty array if no instances are loaded.
  */
 public static function loadCollectionGraph(xPDO &$xpdo, $className, $graph, $criteria, $cacheFlag)
 {
     $objCollection = array();
     if ($query = $xpdo->newQuery($className, $criteria, $cacheFlag)) {
         $query->bindGraph($graph);
         $fromCache = false;
         $collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
             $rows = $xpdo->fromCache($criteria);
             $fromCache = !empty($rows);
         }
         if (!$fromCache && ($stmt = $query->prepare())) {
             if ($stmt->execute()) {
                 $objCollection = $query->hydrateGraph($stmt, $cacheFlag);
             }
         } else {
             $objCollection = $query->hydrateGraph($rows, $cacheFlag);
         }
     }
     return $objCollection;
 }
開發者ID:Kleist,項目名稱:xPDO,代碼行數:37,代碼來源:xpdoobject.class.php


注:本文中的xPDO::fromCache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。