apc.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 ( ! is_null($cache = apc_fetch($this->key.$key))) return $cache;
  38. }
  39. /**
  40. * Write an item to the cache for a given number of minutes.
  41. *
  42. * <code>
  43. * // Put an item in the cache for 15 minutes
  44. * Cache::put('name', 'Taylor', 15);
  45. * </code>
  46. *
  47. * @param string $key
  48. * @param mixed $value
  49. * @param int $minutes
  50. * @return void
  51. */
  52. public function put($key, $value, $minutes)
  53. {
  54. apc_store($this->key.$key, $value, $minutes * 60);
  55. }
  56. /**
  57. * Delete an item from the cache.
  58. *
  59. * @param string $key
  60. * @return void
  61. */
  62. public function forget($key)
  63. {
  64. apc_delete($this->key.$key);
  65. }
  66. }