PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/cache/handler/output.php

https://github.com/joebushi/joomla
PHP | 72 lines | 30 code | 5 blank | 37 comment | 2 complexity | dbeccd68f46f5fa594918258e4629990 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Framework
  5. * @subpackage Cache
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('JPATH_BASE') or die;
  11. /**
  12. * Joomla! Cache output type object
  13. *
  14. * @package Joomla.Framework
  15. * @subpackage Cache
  16. * @since 1.5
  17. */
  18. class JCacheOutput extends JCache
  19. {
  20. /**
  21. * Start the cache
  22. *
  23. * @access public
  24. * @param string $id The cache data id
  25. * @param string $group The cache data group
  26. * @return boolean True if the cache is hit (false else)
  27. * @since 1.5
  28. */
  29. function start($id, $group=null)
  30. {
  31. // If we have data in cache use that...
  32. $data = $this->get($id, $group);
  33. if ($data !== false) {
  34. echo $data;
  35. return true;
  36. } else {
  37. // Nothing in cache... lets start the output buffer and start collecting data for next time.
  38. ob_start();
  39. ob_implicit_flush(false);
  40. // Set id and group placeholders
  41. $this->_id = $id;
  42. $this->_group = $group;
  43. return false;
  44. }
  45. }
  46. /**
  47. * Stop the cache buffer and store the cached data
  48. *
  49. * @access public
  50. * @return boolean True if cache stored
  51. * @since 1.5
  52. */
  53. function end()
  54. {
  55. // Get data from output buffer and echo it
  56. $data = ob_get_contents();
  57. ob_end_clean();
  58. echo $data;
  59. // Get id and group and reset them placeholders
  60. $id = $this->_id;
  61. $group = $this->_group;
  62. $this->_id = null;
  63. $this->_group = null;
  64. // Get the storage handler and store the cached data
  65. $this->store($data, $id, $group);
  66. }
  67. }