home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Cache.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.5 KB  |  88 lines

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer :: Driver :: Cache                             |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // |                         Kristian K÷hntopp <kris@koehntopp.de>.            |
  8. // +---------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,           |
  10. // | that is available at http://www.php.net/license/3_0.txt.                  |
  11. // | If you did not receive a copy of the PHP license and are unable to        |
  12. // | obtain it through the world-wide-web, please send a note to               |
  13. // | license@php.net so we can mail you a copy immediately.                    |
  14. // +---------------------------------------------------------------------------+
  15. //
  16. // $Id: Cache.php,v 1.6 2004/01/01 10:31:54 sebastian Exp $
  17. //
  18.  
  19. require_once 'Cache/Lite.php';
  20. require_once 'XML/Transformer.php';
  21.  
  22. /**
  23. * Caching Transformer.
  24. *
  25. * @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
  26. * @author  Kristian K÷hntopp <kris@koehntopp.de>
  27. * @version $Revision: 1.6 $
  28. * @access  public
  29. */
  30. class XML_Transformer_Driver_Cache extends XML_Transformer {
  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. ?>
  88.