No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ZendDataCache.php 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 mixed|false 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 mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]],
  38. * it could be something else.
  39. * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  40. * @return boolean true if the value is successfully stored into cache, false otherwise
  41. */
  42. protected function setValue($key, $value, $duration)
  43. {
  44. return zend_shm_cache_store($key, $value, $duration);
  45. }
  46. /**
  47. * Stores a value identified by a key into cache if the cache does not contain this key.
  48. * This is the implementation of the method declared in the parent class.
  49. *
  50. * @param string $key the key identifying the value to be cached
  51. * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]],
  52. * it could be something else.
  53. * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  54. * @return boolean true if the value is successfully stored into cache, false otherwise
  55. */
  56. protected function addValue($key, $value, $duration)
  57. {
  58. return zend_shm_cache_fetch($key) === null ? $this->setValue($key, $value, $duration) : false;
  59. }
  60. /**
  61. * Deletes a value with the specified key from cache
  62. * This is the implementation of the method declared in the parent class.
  63. * @param string $key the key of the value to be deleted
  64. * @return boolean if no error happens during deletion
  65. */
  66. protected function deleteValue($key)
  67. {
  68. return zend_shm_cache_delete($key);
  69. }
  70. /**
  71. * Deletes all values from cache.
  72. * This is the implementation of the method declared in the parent class.
  73. * @return boolean whether the flush operation was successful.
  74. */
  75. protected function flushValues()
  76. {
  77. return zend_shm_cache_clear();
  78. }
  79. }