b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _class_itemcache.php

Documentation is available at _class_itemcache.php

  1. <?php
  2. /**
  3.  * Item Cache Class
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once dirname(__FILE__).'/_class_dataobjectcache.php';
  17.  
  18. /**
  19.  * Item Cache Class
  20.  *
  21.  * @package evocore
  22.  */
  23. class ItemCache extends DataObjectCache
  24. {
  25.     var $urltitle_index = array();
  26.  
  27.     /**
  28.      * Constructor
  29.      *
  30.      * {@internal ItemCache::ItemCache(-) }}
  31.      */
  32.     function ItemCache()
  33.     {
  34.         global $tableposts;
  35.         
  36.         parent::DataObjectCache'Item'false$tableposts'post_''ID' );
  37.     }
  38.  
  39.     /**
  40.      * Get an object from cache by its urltitle
  41.      *
  42.      * Load into cache if necessary
  43.      *
  44.      * {@internal ItemCache::get_by_urltitle(-) }}
  45.      *
  46.      * @param string stub of object to load
  47.      * @param boolean false if you want to return false on error
  48.      */
  49.     function get_by_urltitle$req_urltitle$halt_on_error true )
  50.     {
  51.         global $DB;
  52.  
  53.         if!isset$this->urltitle_index[$req_urltitle) )
  54.         // not yet in cache:
  55.             // Load just the requested object:
  56.             debug_log"Loading <strong>$this->objtype($req_urltitle)</strong> into cache);
  57.             $sql "SELECT * 
  58.                             FROM $this->dbtablename 
  59.                             WHERE post_urltitle = ".$DB->quote($req_urltitle);
  60.             $row $DB->get_row$sql );
  61.             ifempty$row ) )
  62.             {    // Requested object does not exist
  63.                 if$halt_on_error die"Requested $this->objtype does not exist!);
  64.                 // put into index:
  65.                 $this->urltitle_index[$req_urltitlefalse;
  66.                 return false;
  67.             }
  68.             
  69.             $dbIDname $this->dbIDname;
  70.             $objtype $this->objtype;
  71.             $this->cache$row->$dbIDname new $objtype$row )// COPY!
  72.             
  73.             // put into index:
  74.             $this->urltitle_index[$req_urltitle$this->cache$row->$dbIDname ];
  75.         }
  76.         else 
  77.         {
  78.             debug_log"Retrieving <strong>$this->objtype($req_urltitle)</strong> from cache);
  79.         }
  80.         
  81.         return $this->urltitle_index[$req_urltitle];
  82.     }
  83.  
  84.  
  85.     /**
  86.      * Load a list of item referenced by their urltitle into the cache
  87.      *
  88.      * {@internal DataObjectCache::load_urltitle_array(-) }}
  89.      *
  90.      * @param array of urltitles of Items to load
  91.      */
  92.     function load_urltitle_array$req_array )
  93.     {
  94.         global $DB;
  95.  
  96.         $req_list "'".implode"','"$req_array)."'";
  97.         debug_log"Loading <strong>$this->objtype($req_list)</strong> into cache);
  98.         $sql "SELECT * FROM $this->dbtablename WHERE post_urltitle IN ( $req_list )";
  99.         $rows $DB->get_results$sql );
  100.         $dbIDname $this->dbIDname;
  101.         $objtype $this->objtype;
  102.         ifcount($rows) ) foreach$rows as $row )
  103.         {
  104.             $this->cache$row->$dbIDname new $objtype$row )// COPY!
  105.             // $obj = $this->cache[ $row->$dbIDname ];
  106.             // $obj->disp( 'name' );
  107.  
  108.             // put into index:
  109.             $this->urltitle_index[$row->post_urltitle$this->cache$row->$dbIDname ];
  110.  
  111.             debug_log"Cached <strong>$this->objtype($row->post_urltitle)</strong>);
  112.         }
  113.         
  114.         // Set cache for non found objects:
  115.         foreach$req_array as $urltitle )
  116.         {
  117.             if!isset$this->urltitle_index[$urltitle) )
  118.             // not yet in cache:
  119.                 $this->urltitle_index[$urltitlefalse// Remember it doesn't exist in DB either
  120.                 debug_log"Cached <strong>$this->objtype($urltitle)</strong> as NON EXISTENT);
  121.             }
  122.         }
  123.     }
  124.  
  125. }
  126. ?>

Documentation generated on Tue, 20 May 2008 01:53:11 +0200 by phpDocumentor 1.4.2