memcached.php 1.2 KB

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