示例#1
0
 function __construct(&$obj)
 {
     if (empty($obj)) {
         die;
     }
     $this->obj = $obj;
     if (empty($obj->model)) {
         $this->model = new mysql($obj->config->db[0]);
     } else {
         $this->model = $obj->model;
     }
     if (empty($obj->mc)) {
         $this->mv = mc();
     } else {
         $this->mc = $obj->mc;
     }
     $this->model->connect();
     $this->cachetime = 86400;
     $this->mc->connectionMemcache($obj->config->memcache["server_list"]["ap1"]["ip"], $obj->config->memcache["server_list"]["ap1"]["port"]);
 }
示例#2
0
/**
 * Caching function. Checks if the key exists in the cache
 * if not - runs the function and caches the result.
 * So, next time it will be there :)
 * @param $function
 * @param $key
 * @param int $timeout
 * @return mixed
 */
function cache($function, $key, $timeout = 300)
{
    $result = mc($key);
    if (!$result) {
        $result = $function();
        if (!empty($result)) {
            mc($key, $result, $timeout);
        }
    }
    return $result;
}