<?php
defined('IN_WEB') or die('Include Error!');
/*
 * 初始化memcache & redis
 */
class ocache {
	public function __construct() {

	}
    /**@var $ocache mucache[]*/
	static $ocache = array();
////////////////////
//	MEMCACHE
///////////////////
	/**
	 * @return mucache
	 */
	public static function cache(){
		if (!is_object( self::$ocache['cache'])) {
			include_once PATH_LIB . 'class.mucache.php';
			self::$ocache['cache'] = new mucache( oo::$config['memcache']);
		}
		return self::$ocache['cache'];
	}

    /**
     * Notes:
     * User: wsc
     * Time: 2020/3/26 14:35
     * @param int $uid
     * @return  mucache
     */
	public static function t_userinfo( $uid=0){
		$id = $uid % 3;
		if (!is_object( self::$ocache['t_userinfo'][$id])) {
			include_once PATH_LIB . 'class.mucache.php';
			self::$ocache['t_userinfo'][$id] = new mucache( oo::$config['t_userinfo'][$id]);
		}
		return self::$ocache['t_userinfo'][$id];
	}

	/**
	 * 用户基本信息
	 * @return mucache
	 */
	public static function minfo($mid = 0){

        /** 采用取模散列的方式将用户信息放在不同的redis中*/
		$prefix = intval( $mid % 5);
		if (!is_object( self::$ocache['minfos'][$prefix])) {
			include_once PATH_LIB . 'class.mucache.php';
			self::$ocache['minfos'][$prefix] = new mucache( oo::$config['minfos'][$prefix]);
		}
		return self::$ocache['minfos'][$prefix];
	}
	
}
