Exemplo n.º 1
0
 /**
  * Returns a registry record by Name and Module Id
  * The result is cached.
  *
  * @param type $name
  * @param type $moduleId
  * @return \HSetting
  */
 private static function GetRecord($name, $moduleId = "")
 {
     $cacheId = 'HSetting_' . $name . '_' . $moduleId;
     // Check if stored in Runtime Cache
     if (RuntimeCache::Get($cacheId) !== false) {
         return RuntimeCache::Get($cacheId);
     }
     // Check if stored in Cache
     $cacheValue = Yii::app()->cache->get($cacheId);
     if ($cacheValue !== false) {
         return $cacheValue;
     }
     $condition = "";
     $params = array('name' => $name);
     if ($moduleId != "") {
         $params['module_id'] = $moduleId;
     } else {
         $condition = "module_id IS NULL or module_id = ''";
     }
     $record = HSetting::model()->findByAttributes($params, $condition);
     if ($record == null) {
         $record = new HSetting();
         $record->name = $name;
         $record->module_id = $moduleId;
     }
     $expireTime = 3600;
     if ($record->name != 'expireTime' && $record->module_id != "cache") {
         $expireTime = HSetting::Get('expireTime', 'cache');
     }
     Yii::app()->cache->set($cacheId, $record, $expireTime);
     RuntimeCache::Set($cacheId, $record);
     return $record;
 }
 /**
  * Returns the RoomMembership Record for this Room
  *
  * If none Record is found, null is given
  */
 public function getMembership($userId = "")
 {
     if ($userId == "") {
         $userId = Yii::app()->user->id;
     }
     $rCacheId = 'RoomMembership_' . $userId . "_" . $this->getOwner()->id;
     $rCacheRes = RuntimeCache::Get($rCacheId);
     if ($rCacheRes != null) {
         return $rCacheRes;
     }
     $dbResult = RoomMembership::model()->findByAttributes(array('user_id' => $userId, 'room_id' => $this->getOwner()->id));
     RuntimeCache::Set($rCacheId, $dbResult);
     return $dbResult;
 }