apc.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php namespace Laravel\Cache\Drivers;
  2. class APC extends Driver {
  3. /**
  4. * The cache key from the cache configuration file.
  5. *
  6. * @var string
  7. */
  8. protected $key;
  9. /**
  10. * Create a new APC cache driver instance.
  11. *
  12. * @param string $key
  13. * @return void
  14. */
  15. public function __construct($key)
  16. {
  17. $this->key = $key;
  18. }
  19. /**
  20. * Determine if an item exists in the cache.
  21. *
  22. * @param string $key
  23. * @return bool
  24. */
  25. public function has($key)
  26. {
  27. return ( ! is_null($this->get($key)));
  28. }
  29. /**
  30. * Retrieve an item from the cache driver.
  31. *
  32. * @param string $key
  33. * @return mixed
  34. */
  35. protected function retrieve($key)
  36. {
  37. if (($cache = apc_fetch($this->key.$key)) !== false)
  38. {
  39. return $cache;
  40. }
  41. }
  42. /**
  43. * Write an item to the cache for a given number of minutes.
  44. *
  45. * <code>
  46. * // Put an item in the cache for 15 minutes
  47. * Cache::put('name', 'Taylor', 15);
  48. * </code>
  49. *
  50. * @param string $key
  51. * @param mixed $value
  52. * @param int $minutes
  53. * @return void
  54. */
  55. public function put($key, $value, $minutes)
  56. {
  57. apc_store($this->key.$key, $value, $minutes * 60);
  58. }
  59. /**
  60. * Delete an item from the cache.
  61. *
  62. * @param string $key
  63. * @return void
  64. */
  65. public function forget($key)
  66. {
  67. apc_delete($this->key.$key);
  68. }
  69. }