Example #1
0
bool CacheManagerI::loadListCache(const std::string& key, const std::string& namespace_id, const std::string& business_id, bool use_master, const Ice::Current& current) {
  std::ostringstream otem;
  otem << "CacheManageI::loadListCache() key:" << key
       << "\tnamespace_id:" << namespace_id 
       << "\tbusiness_id:" << business_id;
  MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, otem.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
  ProducerManagerClientPtr producer = getProducer();
  if(producer == NULL) {
      return false;
  }
  KeySeq keys;
  keys.push_back(key);
  DataMap data = producer->produce(keys, business_id, use_master, 0);
  if (data.empty()) {
    return true;
  } 
  std::string list_key;
  StrList list_value;
  DataMap::const_iterator iter = data.begin();
  list_key = iter->second;
  for (; iter != data.end(); ++iter) {
    list_value.push_back(iter->first);
  }
  RedisCacheClientPtr redis_client = GetRedisCache(); 
  redis_client->Set(list_key, list_value, namespace_id, business_id);
  return true;
}
Example #2
0
bool CacheManagerI::load(const KeySeq& keys, const std::string& namespaceId, const std::string& businessId, 
                long expiredTime, bool useMaster, const Ice::Current& current) {
    std::ostringstream os;
    os<<"Key : ";
    for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) {
        os<<*it<<" ";
    }
    os<<" namespaceId :"<<namespaceId;
    os<<" businessId :"<<businessId;
    os<<" expiredTime :"<<expiredTime;
    os<<" useMaster :"<<useMaster;
    MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
    ProducerManagerClientPtr producer = getProducer();
    if(producer == NULL) {
        return false;
    }
    
    bool sucFlag = true;

    KeySeq inputKeys(keys.begin(), keys.end());
    KeySeq lockedKeys;
    KeySeq failedLockedKeys;
    DataMap res;
    
    while(true) {
        xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, inputKeys, lockedKeys, failedLockedKeys);
        if(!lockedKeys.empty()) {
            DataMap singleRes = producer->produce(keys, businessId, useMaster, 1000);
            if(!singleRes.empty()) {
                res.insert(singleRes.begin(), singleRes.end());
            }
        
            CacheClientPtr cache = getCache();
            if(cache != NULL) {
                for(DataMap::const_iterator it = singleRes.begin(); it != singleRes.end(); ++it) {
                    sucFlag &= cache->set(it->first, it->second, namespaceId, businessId, expiredTime, 1000);
                }
            }
            if(failedLockedKeys.empty()) {
                break;
            }
        }
        inputKeys.swap(failedLockedKeys);
        lockedKeys.clear();
        failedLockedKeys.clear();
    }

    return sucFlag;
}
vector<MenuTripodDataPtr> MenuCacheManagerI::getWithUserId(int userId, const CacheTypeSeq& types) {
  vector<MenuTripodDataPtr> result;
  for (CacheTypeSeq::const_iterator it = types.begin(); it != types.end(); ++it) {
    int category = getObjCacheCategoryWithCacheType(*it);
    if (category == -1) {
      continue;
    }
    string cacheTypeStr = TripodHelper::getCacheTypeStr(*it);
    MenuTripodDataPtr ptr = ServiceI::instance().findObject<MenuTripodDataPtr>(category, userId);
    if (ptr != 0) {
      //MCE_INFO("[MenuCacheManagerI::getWithUserId] userId = " << userId << ", cacheType = " <<  cacheTypeStr
      //    << " found in ObjectCache");
      result.push_back(ptr);
    } else {
      TripodClient* tripodClient = getTripodClientWithCacheType(*it);
      KeySeq missedKeys, keys;
      keys.push_back(boost::lexical_cast<string>(userId));
      DataMap dataMap = tripodClient->get(keys, missedKeys);
      if (!missedKeys.empty()) {
        addKeysToLoad(missedKeys, *it);
      }
      if (dataMap.empty()) {
        //MCE_INFO("[MenuCacheManagerI::getWithUserId] userId = " << userId << ", cacheType = " << cacheTypeStr
        //    << ", not found in TripodCache");
        result.push_back(new MenuTripodData(userId, *it));
      } else {
        //MCE_INFO("[MenuCacheManagerI::getWithUserId] userId = " << userId << ", cacheType = " << cacheTypeStr
        //    << ", found in TripodCache");
        for (DataMap::const_iterator itx = dataMap.begin(); itx != dataMap.end(); ++itx) {
          string byteArray(itx->second.begin(), itx->second.end());
          MenuTripodDataPtr tempPtr = new MenuTripodData(byteArray);
          result.push_back(tempPtr);
        }
      }
    }
  }
  return result;
}