/** * 静态方法, 单例统一访问入口 * @return object 返回对象的唯一实例 */ public static function getInstance() { if (is_null(self::$_instance) || !isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * 判断是否向db读取数据 * 返回值为true表示从db中获得,否则从cache中获得 * @param int $deviceId * @return boolean */ public function check2Db($userId, $deviceId, $eventId) { $cacheUserId = $this->get($this->getUserKey($userId)); $cacheEventId = $this->get($this->getDeviceEventKey($deviceId)); if ($cacheUserId == false || $cacheEventId == false) { //当3者之一都不存在记录, return true; } $userMaxId = MiniEvent2::getInstance()->getMaxIdByUser2($userId); if ($cacheUserId != $userMaxId || $cacheEventId != $eventId) { return true; } return false; }