DummyCache.php 2.8 KB

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. * DummyCache is a placeholder cache component.
  10. *
  11. * DummyCache does not cache anything. It is provided so that one can always configure
  12. * a 'cache' application component and save the check of existence of `\Yii::$app->cache`.
  13. * By replacing DummyCache with some other cache component, one can quickly switch from
  14. * non-caching mode to caching mode.
  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. */
  21. class DummyCache extends Cache
  22. {
  23. /**
  24. * Retrieves a value from cache with a specified key.
  25. * This is the implementation of the method declared in the parent class.
  26. * @param string $key a unique key identifying the cached value
  27. * @return mixed|false the value stored in cache, false if the value is not in the cache or expired.
  28. */
  29. protected function getValue($key)
  30. {
  31. return false;
  32. }
  33. /**
  34. * Stores a value identified by a key in cache.
  35. * This is the implementation of the method declared in the parent class.
  36. *
  37. * @param string $key the key identifying the value to be cached
  38. * @param mixed $value the value to be cached
  39. * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire.
  40. * @return bool true if the value is successfully stored into cache, false otherwise
  41. */
  42. protected function setValue($key, $value, $duration)
  43. {
  44. return true;
  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. * @param string $key the key identifying the value to be cached
  50. * @param mixed $value the value to be cached
  51. * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire.
  52. * @return bool true if the value is successfully stored into cache, false otherwise
  53. */
  54. protected function addValue($key, $value, $duration)
  55. {
  56. return true;
  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 bool if no error happens during deletion
  63. */
  64. protected function deleteValue($key)
  65. {
  66. return true;
  67. }
  68. /**
  69. * Deletes all values from cache.
  70. * This is the implementation of the method declared in the parent class.
  71. * @return bool whether the flush operation was successful.
  72. */
  73. protected function flushValues()
  74. {
  75. return true;
  76. }
  77. }