memcached.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php namespace Laravel\Cache;
  2. use Laravel\Config;
  3. use Laravel\Memcached as Mem;
  4. class Memcached extends Driver {
  5. /**
  6. * Determine if an item exists in the cache.
  7. *
  8. * <code>
  9. * // Determine if the "name" item exists in the cache
  10. * $exists = Cache::driver()->has('name');
  11. * </code>
  12. *
  13. * @param string $key
  14. * @return bool
  15. */
  16. public function has($key)
  17. {
  18. return ( ! is_null($this->get($key)));
  19. }
  20. /**
  21. * Retrieve an item from the cache driver.
  22. *
  23. * @param string $key
  24. * @return mixed
  25. */
  26. protected function retrieve($key)
  27. {
  28. return (($cache = Mem::instance()->get(Config::get('cache.key').$key)) !== false) ? $cache : null;
  29. }
  30. /**
  31. * Write an item to the cache for a given number of minutes.
  32. *
  33. * <code>
  34. * // Write the "name" item to the cache for 30 minutes
  35. * Cache::driver()->put('name', 'Fred', 30);
  36. * </code>
  37. *
  38. * @param string $key
  39. * @param mixed $value
  40. * @param int $minutes
  41. * @return void
  42. */
  43. public function put($key, $value, $minutes)
  44. {
  45. Mem::instance()->set(Config::get('cache.key').$key, $value, 0, $minutes * 60);
  46. }
  47. /**
  48. * Delete an item from the cache.
  49. *
  50. * @param string $key
  51. * @return void
  52. */
  53. public function forget($key)
  54. {
  55. Mem::instance()->delete(Config::get('cache.key').$key);
  56. }
  57. }