Guest User

Untitled

a guest
Dec 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. class Cache
  4. {
  5.  
  6. private $memcached;
  7.  
  8. const SERVER = 'localhost';
  9. const PORT = 11211;
  10.  
  11. public function __construct()
  12. {
  13.  
  14. try {
  15.  
  16. $this->memcached = new Memcached();
  17. $this->memcached->addServer(self::SERVER, self::PORT);
  18.  
  19. } catch (MemcachedException $e) {
  20.  
  21. die('Error ocurred while set memcached instance, error code: '.$e->getCode());
  22.  
  23. }
  24.  
  25. }
  26.  
  27. public function set($key, $value)
  28. {
  29.  
  30. $this->memcached->set($key, $value);
  31.  
  32. }
  33.  
  34. public function get($key)
  35. {
  36.  
  37. return $this->memcached->get($key);
  38.  
  39. }
  40.  
  41. public function clear()
  42. {
  43.  
  44. $this->memcached->flush();
  45.  
  46. }
  47.  
  48. }
Add Comment
Please, Sign In to add comment