apc.php 1.3 KB

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