Cache.inc 559 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. class Cache {
  3. private $memcached;
  4. public function __construct() {
  5. if(!$this->memcached) {
  6. $this->memcached = new Memcached();
  7. }
  8. }
  9. public function connect() {
  10. $servers = $this->memcached->getServerList();
  11. if(is_array($servers)) {
  12. foreach($servers as $server) {
  13. return true;
  14. }
  15. }
  16. $this->memcached->addServer(MEMCACHED_SERVER, MEMCACHED_PORT);
  17. }
  18. public function get($key) {
  19. return $this->memcached->get($key);
  20. }
  21. public function set($key, $value, $expiration) {
  22. $this->memcached->set($key, $value, $expiration);
  23. }
  24. }