Disk.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_Cache
  17. * @subpackage Zend_Cache_Backend
  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. */
  21. /** @see Zend_Cache_Backend_Interface */
  22. require_once 'Zend/Cache/Backend/Interface.php';
  23. /** @see Zend_Cache_Backend_ZendServer */
  24. require_once 'Zend/Cache/Backend/ZendServer.php';
  25. /**
  26. * @package Zend_Cache
  27. * @subpackage Zend_Cache_Backend
  28. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
  32. {
  33. /**
  34. * Constructor
  35. *
  36. * @param array $options associative array of options
  37. * @throws Zend_Cache_Exception
  38. */
  39. public function __construct(array $options = array())
  40. {
  41. if (!function_exists('zend_disk_cache_store')) {
  42. Zend_Cache::throwException('Zend_Cache_ZendServer_Disk backend has to be used within Zend Server environment.');
  43. }
  44. parent::__construct($options);
  45. }
  46. /**
  47. * Store data
  48. *
  49. * @var mixed $data Object to store
  50. * @var string $id Cache id
  51. * @var int $timeToLive Time to live in seconds
  52. * @return boolean true if no problem
  53. */
  54. protected function _store($data, $id, $timeToLive)
  55. {
  56. if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id,
  57. $data,
  58. $timeToLive) === false) {
  59. $this->_log('Store operation failed.');
  60. return false;
  61. }
  62. return true;
  63. }
  64. /**
  65. * Fetch data
  66. *
  67. * @var mixed $data Object to store
  68. * @var string $id Cache id
  69. * @var int $timeToLive Time to live in seconds
  70. */
  71. protected function _fetch($id)
  72. {
  73. return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id);
  74. }
  75. /**
  76. * Unset data
  77. *
  78. * @var string $id Cache id
  79. * @return boolean true if no problem
  80. */
  81. protected function _unset($id)
  82. {
  83. return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id);
  84. }
  85. /**
  86. * Clear cache
  87. */
  88. protected function _clear()
  89. {
  90. zend_disk_cache_clear($this->_options['namespace']);
  91. }
  92. }