file.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php namespace Laravel\Cache\Drivers; use Laravel\File as F;
  2. class File extends Driver {
  3. /**
  4. * The path to which the cache files should be written.
  5. *
  6. * @var string
  7. */
  8. private $path;
  9. /**
  10. * Create a new File cache driver instance.
  11. *
  12. * @param string $path
  13. * @return void
  14. */
  15. public function __construct($path)
  16. {
  17. $this->path = $path;
  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 ( ! F::exists($this->path.$key)) return null;
  38. if (time() >= substr($cache = F::get($this->path.$key), 0, 10))
  39. {
  40. return $this->forget($key);
  41. }
  42. return unserialize(substr($cache, 10));
  43. }
  44. /**
  45. * Write an item to the cache for a given number of minutes.
  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. F::put($this->path.$key, (time() + ($minutes * 60)).serialize($value));
  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. F::delete($this->path.$key);
  65. }
  66. }