ApcStore.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. return $this->apc->get($this->prefix.$key);
  39. }
  40. /**
  41. * Store an item in the cache for a given number of seconds.
  42. *
  43. * @param string $key
  44. * @param mixed $value
  45. * @param int $seconds
  46. * @return bool
  47. */
  48. public function put($key, $value, $seconds)
  49. {
  50. return $this->apc->put($this->prefix.$key, $value, $seconds);
  51. }
  52. /**
  53. * Increment the value of an item in the cache.
  54. *
  55. * @param string $key
  56. * @param mixed $value
  57. * @return int|bool
  58. */
  59. public function increment($key, $value = 1)
  60. {
  61. return $this->apc->increment($this->prefix.$key, $value);
  62. }
  63. /**
  64. * Decrement the value of an item in the cache.
  65. *
  66. * @param string $key
  67. * @param mixed $value
  68. * @return int|bool
  69. */
  70. public function decrement($key, $value = 1)
  71. {
  72. return $this->apc->decrement($this->prefix.$key, $value);
  73. }
  74. /**
  75. * Store an item in the cache indefinitely.
  76. *
  77. * @param string $key
  78. * @param mixed $value
  79. * @return bool
  80. */
  81. public function forever($key, $value)
  82. {
  83. return $this->put($key, $value, 0);
  84. }
  85. /**
  86. * Remove an item from the cache.
  87. *
  88. * @param string $key
  89. * @return bool
  90. */
  91. public function forget($key)
  92. {
  93. return $this->apc->delete($this->prefix.$key);
  94. }
  95. /**
  96. * Remove all items from the cache.
  97. *
  98. * @return bool
  99. */
  100. public function flush()
  101. {
  102. return $this->apc->flush();
  103. }
  104. /**
  105. * Get the cache key prefix.
  106. *
  107. * @return string
  108. */
  109. public function getPrefix()
  110. {
  111. return $this->prefix;
  112. }
  113. }