ApcStore.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Illuminate\Cache;
  3. class ApcStore extends TaggableStore
  4. {
  5. use RetrievesMultipleKeys;
  6. /**
  7. * The APC wrapper instance.
  8. *
  9. * @var \Illuminate\Cache\ApcWrapper
  10. */
  11. protected $apc;
  12. /**
  13. * A string that should be prepended to keys.
  14. *
  15. * @var string
  16. */
  17. protected $prefix;
  18. /**
  19. * Create a new APC store.
  20. *
  21. * @param \Illuminate\Cache\ApcWrapper $apc
  22. * @param string $prefix
  23. * @return void
  24. */
  25. public function __construct(ApcWrapper $apc, $prefix = '')
  26. {
  27. $this->apc = $apc;
  28. $this->prefix = $prefix;
  29. }
  30. /**
  31. * Retrieve an item from the cache by key.
  32. *
  33. * @param string|array $key
  34. * @return mixed
  35. */
  36. public function get($key)
  37. {
  38. $value = $this->apc->get($this->prefix.$key);
  39. if ($value !== false) {
  40. return $value;
  41. }
  42. }
  43. /**
  44. * Store an item in the cache for a given number of seconds.
  45. *
  46. * @param string $key
  47. * @param mixed $value
  48. * @param int $seconds
  49. * @return bool
  50. */
  51. public function put($key, $value, $seconds)
  52. {
  53. return $this->apc->put($this->prefix.$key, $value, $seconds);
  54. }
  55. /**
  56. * Increment the value of an item in the cache.
  57. *
  58. * @param string $key
  59. * @param mixed $value
  60. * @return int|bool
  61. */
  62. public function increment($key, $value = 1)
  63. {
  64. return $this->apc->increment($this->prefix.$key, $value);
  65. }
  66. /**
  67. * Decrement the value of an item in the cache.
  68. *
  69. * @param string $key
  70. * @param mixed $value
  71. * @return int|bool
  72. */
  73. public function decrement($key, $value = 1)
  74. {
  75. return $this->apc->decrement($this->prefix.$key, $value);
  76. }
  77. /**
  78. * Store an item in the cache indefinitely.
  79. *
  80. * @param string $key
  81. * @param mixed $value
  82. * @return bool
  83. */
  84. public function forever($key, $value)
  85. {
  86. return $this->put($key, $value, 0);
  87. }
  88. /**
  89. * Remove an item from the cache.
  90. *
  91. * @param string $key
  92. * @return bool
  93. */
  94. public function forget($key)
  95. {
  96. return $this->apc->delete($this->prefix.$key);
  97. }
  98. /**
  99. * Remove all items from the cache.
  100. *
  101. * @return bool
  102. */
  103. public function flush()
  104. {
  105. return $this->apc->flush();
  106. }
  107. /**
  108. * Get the cache key prefix.
  109. *
  110. * @return string
  111. */
  112. public function getPrefix()
  113. {
  114. return $this->prefix;
  115. }
  116. }