選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ZendDataCache.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @since 2.0
  18. */
  19. class ZendDataCache extends Cache
  20. {
  21. /**
  22. * Retrieves a value from cache with a specified key.
  23. * This is the implementation of the method declared in the parent class.
  24. * @param string $key a unique key identifying the cached value
  25. * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
  26. */
  27. protected function getValue($key)
  28. {
  29. $result = zend_shm_cache_fetch($key);
  30. return $result === null ? false : $result;
  31. }
  32. /**
  33. * Stores a value identified by a key in cache.
  34. * This is the implementation of the method declared in the parent class.
  35. *
  36. * @param string $key the key identifying the value to be cached
  37. * @param string $value the value to be cached
  38. * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  39. * @return boolean true if the value is successfully stored into cache, false otherwise
  40. */
  41. protected function setValue($key, $value, $duration)
  42. {
  43. return zend_shm_cache_store($key, $value, $duration);
  44. }
  45. /**
  46. * Stores a value identified by a key into cache if the cache does not contain this key.
  47. * This is the implementation of the method declared in the parent class.
  48. *
  49. * @param string $key the key identifying the value to be cached
  50. * @param string $value the value to be cached
  51. * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  52. * @return boolean true if the value is successfully stored into cache, false otherwise
  53. */
  54. protected function addValue($key, $value, $duration)
  55. {
  56. return zend_shm_cache_fetch($key) === null ? $this->setValue($key, $value, $duration) : false;
  57. }
  58. /**
  59. * Deletes a value with the specified key from cache
  60. * This is the implementation of the method declared in the parent class.
  61. * @param string $key the key of the value to be deleted
  62. * @return boolean if no error happens during deletion
  63. */
  64. protected function deleteValue($key)
  65. {
  66. return zend_shm_cache_delete($key);
  67. }
  68. /**
  69. * Deletes all values from cache.
  70. * This is the implementation of the method declared in the parent class.
  71. * @return boolean whether the flush operation was successful.
  72. */
  73. protected function flushValues()
  74. {
  75. return zend_shm_cache_clear();
  76. }
  77. }