file.php 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php namespace Laravel\Cache;
  2. class File extends Driver {
  3. public function has($key)
  4. {
  5. return ( ! is_null($this->get($key)));
  6. }
  7. public function get($key, $default = null)
  8. {
  9. if ( ! file_exists(CACHE_PATH.$key))
  10. {
  11. return $this->prepare(null, $default);
  12. }
  13. $cache = file_get_contents(CACHE_PATH.$key);
  14. // The cache expiration date is stored as a UNIX timestamp at the beginning
  15. // of the cache file. We'll extract it out and check it here.
  16. if (time() >= substr($cache, 0, 10))
  17. {
  18. $this->forget($key);
  19. return $this->prepare(null, $default);
  20. }
  21. return $this->prepare(unserialize(substr($cache, 10)), $default);
  22. }
  23. public function put($key, $value, $minutes)
  24. {
  25. file_put_contents(CACHE_PATH.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX);
  26. }
  27. public function forget($key)
  28. {
  29. @unlink(CACHE_PATH.$key);
  30. }
  31. }