| 1 | <?php |
||
| 11 | class Memcached extends BaseDriver |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var \Memcached |
||
| 15 | */ |
||
| 16 | protected $memcached; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $prefix; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param \Memcached $memcached |
||
| 25 | * @param string $prefix |
||
| 26 | */ |
||
| 27 | 6 | public function __construct(\Memcached $memcached, $prefix) |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $key |
||
| 35 | * |
||
| 36 | * @return \DateTime|null |
||
| 37 | */ |
||
| 38 | 3 | public function get($key) |
|
| 39 | { |
||
| 40 | 3 | $key = $this->prefix.$key; |
|
| 41 | 3 | if ($time = $this->memcached->get($key)) { |
|
| 42 | return (new \DateTime())->setTimestamp($time); |
||
| 43 | } |
||
| 44 | |||
| 45 | return null; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $key |
||
| 50 | * @param \DateTime $time |
||
| 51 | * |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | 1 | public function set($key, \DateTime $time) |
|
| 55 | { |
||
| 56 | 1 | $key = $this->prefix.$key; |
|
| 57 | 1 | if (!($old_time = $this->memcached->get($key)) || $old_time < $time->getTimestamp()) { |
|
| 58 | 1 | return $this->memcached->set($key, $time->getTimestamp()); |
|
| 59 | } |
||
| 60 | |||
| 61 | return true; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param string $key |
||
| 66 | * |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | 1 | public function remove($key) |
|
| 73 | } |
||
| 74 |