Cachemanager.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Application
  17. * @subpackage Resource
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Application/Resource/ResourceAbstract.php';
  23. /**
  24. * Cache Manager resource
  25. *
  26. * @category Zend
  27. * @package Zend_Application
  28. * @subpackage Resource
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Application_Resource_Cachemanager extends Zend_Application_Resource_ResourceAbstract
  33. {
  34. /**
  35. * @var Zend_Cache_Manager
  36. */
  37. protected $_manager = null;
  38. /**
  39. * Initialize Cache_Manager
  40. *
  41. * @return Zend_Cache_Manager
  42. */
  43. public function init()
  44. {
  45. $manager = $this->getCacheManager();
  46. foreach ($this->getOptions() as $key => $value) {
  47. if ($manager->hasCacheTemplate($key)) {
  48. $manager->setTemplateOptions($key, $value);
  49. } else {
  50. $manager->setCacheTemplate($key, $value);
  51. }
  52. }
  53. if (null !== ($bootstrap = $this->getBootstrap())) {
  54. $this->getBootstrap()->cacheManager = $manager;
  55. }
  56. return $manager;
  57. }
  58. /**
  59. * Retrieve front controller instance
  60. *
  61. * @return Zend_Controller_Front
  62. */
  63. public function getCacheManager()
  64. {
  65. if (null === $this->_manager) {
  66. $this->_manager = new Zend_Cache_Manager;
  67. }
  68. return $this->_manager;
  69. }
  70. }