ZendDataCache.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\caching;
  8. /**
  9. * ZendDataCache provides Zend data caching in terms of an application component.
  10. *
  11. * To use this application component, the [Zend Data Cache PHP extension](http://www.zend.com/en/products/server/)
  12. * must be loaded.
  13. *
  14. * See [[Cache]] for common cache operations that ZendDataCache supports.
  15. *
  16. * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
  17. *
  18. * @author Qiang Xue <qiang.xue@gmail.com>
  19. * @since 2.0
  20. * @deprecated since 2.0.14. This class will be removed in 2.1.0.
  21. */
  22. class ZendDataCache extends Cache
  23. {
  24. /**
  25. * Retrieves a value from cache with a specified key.
  26. * This is the implementation of the method declared in the parent class.
  27. * @param string $key a unique key identifying the cached value
  28. * @return mixed|false the value stored in cache, false if the value is not in the cache or expired.
  29. */
  30. protected function getValue($key)
  31. {
  32. $result = zend_shm_cache_fetch($key);
  33. return $result === null ? false : $result;
  34. }
  35. /**
  36. * Stores a value identified by a key in cache.
  37. * This is the implementation of the method declared in the parent class.
  38. *
  39. * @param string $key the key identifying the value to be cached
  40. * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]],
  41. * it could be something else.
  42. * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire.
  43. * @return bool true if the value is successfully stored into cache, false otherwise
  44. */
  45. protected function setValue($key, $value, $duration)
  46. {
  47. return zend_shm_cache_store($key, $value, $duration);
  48. }
  49. /**
  50. * Stores a value identified by a key into cache if the cache does not contain this key.
  51. * This is the implementation of the method declared in the parent class.
  52. *
  53. * @param string $key the key identifying the value to be cached
  54. * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]],
  55. * it could be something else.
  56. * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire.
  57. * @return bool true if the value is successfully stored into cache, false otherwise
  58. */
  59. protected function addValue($key, $value, $duration)
  60. {
  61. return zend_shm_cache_fetch($key) === null ? $this->setValue($key, $value, $duration) : false;
  62. }
  63. /**
  64. * Deletes a value with the specified key from cache
  65. * This is the implementation of the method declared in the parent class.
  66. * @param string $key the key of the value to be deleted
  67. * @return bool if no error happens during deletion
  68. */
  69. protected function deleteValue($key)
  70. {
  71. return zend_shm_cache_delete($key);
  72. }
  73. /**
  74. * Deletes all values from cache.
  75. * This is the implementation of the method declared in the parent class.
  76. * @return bool whether the flush operation was successful.
  77. */
  78. protected function flushValues()
  79. {
  80. return zend_shm_cache_clear();
  81. }
  82. }