XML_Transformer
[ class tree: XML_Transformer ] [ index: XML_Transformer ] [ all elements ]

Source for file Cache.php

Documentation is available at Cache.php

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer :: Driver :: Cache                             |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // +---------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,           |
  9. // | that is available at http://www.php.net/license/3_0.txt.                  |
  10. // | If you did not receive a copy of the PHP license and are unable to        |
  11. // | obtain it through the world-wide-web, please send a note to               |
  12. // | license@php.net so we can mail you a copy immediately.                    |
  13. // +---------------------------------------------------------------------------+
  14. //
  15. // $Id$
  16. //
  17.  
  18. require_once 'Cache/Lite.php';
  19. require_once 'XML/Transformer.php';
  20.  
  21.  /**
  22.  * Caching Transformer.
  23.  *
  24.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  25.  * @author
  26.  * @copyright
  27.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  28.  * @category    XML
  29.  * @package     XML_Transformer
  30.  */
  31.     // {{{ Members
  32.  
  33.     /**
  34.     * @var    object 
  35.     * @access private
  36.     */
  37.     var $_cache = FALSE;
  38.  
  39.     // }}}
  40.     // {{{ function XML_Transformer_Driver_Cache($parameters = array())
  41.  
  42.     /**
  43.     * Constructor.
  44.     *
  45.     * @param  array 
  46.     * @access public
  47.     */
  48.     function XML_Transformer_Driver_Cache($parameters = array()) {
  49.         $this->XML_Transformer($parameters);
  50.         $this->_cache = new Cache_Lite($parameters);
  51.     }
  52.  
  53.     // }}}
  54.     // {{{ function transform($xml, $cacheID = '')
  55.  
  56.     /**
  57.     * Cached transformation a given XML string using
  58.     * the registered PHP callbacks for overloaded tags.
  59.     *
  60.     * @param  string 
  61.     * @param  string 
  62.     * @return string 
  63.     * @access public
  64.     */
  65.     function transform($xml$cacheID ''{
  66.         $cacheID ($cacheID != ''$cacheID md5($xml);
  67.  
  68.         $cachedResult $this->_cache->get($cacheID'XML_Transformer');
  69.  
  70.         if ($cachedResult !== FALSE{
  71.             return $cachedResult;
  72.         }
  73.  
  74.         $result = parent::transform($xml);
  75.         $this->_cache->save($result$cacheID'XML_Transformer');
  76.  
  77.         return $result;
  78.     }
  79.  
  80.     // }}}
  81. }
  82.  
  83. /*
  84.  * vim600:  et sw=2 ts=2 fdm=marker
  85.  * vim<600: et sw=2 ts=2
  86.  */
  87. ?>

Documentation generated on Mon, 11 Mar 2019 15:48:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.