memcached.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php namespace Laravel\Session;
  2. use Laravel\Config;
  3. class Memcached extends Driver {
  4. /**
  5. * The Memcache cache driver instance.
  6. *
  7. * @var Memcached
  8. */
  9. private $memcached;
  10. /**
  11. * Create a new Memcached session driver instance.
  12. *
  13. * @param Memcached $memcached
  14. * @return void
  15. */
  16. public function __construct(\Laravel\Cache\Memcached $memcached)
  17. {
  18. $this->memcached = $memcached;
  19. }
  20. /**
  21. * Load a session by ID.
  22. *
  23. * The session will be retrieved from persistant storage and returned as an array.
  24. * The array contains the session ID, last activity UNIX timestamp, and session data.
  25. *
  26. * @param string $id
  27. * @return array
  28. */
  29. protected function load($id)
  30. {
  31. return $this->memcached->get($id);
  32. }
  33. /**
  34. * Save the session to persistant storage.
  35. *
  36. * @return void
  37. */
  38. protected function save()
  39. {
  40. $this->memcached->put($this->session['id'], $this->session, Config::get('session.lifetime'));
  41. }
  42. /**
  43. * Delete the session from persistant storage.
  44. *
  45. * @return void
  46. */
  47. protected function delete()
  48. {
  49. $this->memcached->forget($this->session['id']);
  50. }
  51. }