Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
lwl12 authored Nov 28, 2018
1 parent 5fe1056 commit 59f577d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/cache/memcache_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
class memcache_{
private $m;

function __construct($config = null){
$this->m = new Memcache();
if(empty($config)){
$config = 'localhost:11211';
}
list($host, $port) = explode(':', $config, 2);
$this->m->addServer($host, $port);
}

function get($key){
$data = $this->m->get($key);
if( is_array($data) && $data['expire'] > time() && !is_null($data['data']) ){
return $data['data'];
}else{
return null;
}
}

function set($key, $value=null, $expire=99999999){
$data['expire'] = time() + $expire;
$data['data'] = $value;
return $this->m->set($key, $data);
}

function clear(){
$this->m->flush(10);
}
}

0 comments on commit 59f577d

Please sign in to comment.