/**
  * 
  * @param Advertisement or AdvertisementDenormalizedProperty $advertisement
  */
 private function invalidateAdsCache($advertisement)
 {
     $advertisementType = $advertisement->getAdvertisementType()->getId();
     $memcacheKey = FrontendMemcacheKeysHelper::getAdvertisementKeyByType($advertisementType);
     if (!$memcacheKey) {
         $denormalizedAd = $advertisement instanceof AdvertisementDenormalizedProperty ? $advertisement : $this->get('services.advertisement')->getDenomralizedPropertyById($advertisement->getId());
         switch ($advertisementType) {
             case AdvertisementTypes::SEARCH_RESULTS_SPECIALIZATION_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSpecializationFeaturedAdsKey($denormalizedAd->getSpecializationId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_SUBSPECIALIZATION_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSubSpecializationFeaturedAdsKey($denormalizedAd->getSubSpecializationId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_TREATMENT_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsTreatmentFeaturedAdsKey($denormalizedAd->getTreatmentId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_CITY_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCityFeaturedAdsKey($denormalizedAd->getCityId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_CITY_SPECIALIZATION_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySpecializationFeaturedAdsKey($denormalizedAd->getCityId(), $denormalizedAd->getSpecializationId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_CITY_SUBSPECIALIZATION_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySubSpecializationFeaturedAdsKey($denormalizedAd->getCityId(), $denormalizedAd->getSubSpecializationId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_CITY_TREATMENT_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCityTreatmentFeaturedAdsKey($denormalizedAd->getCityId(), $denormalizedAd->getTreatmentId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountryFeaturedAdsKey($denormalizedAd->getCountryId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_SPECIALIZATION_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySpecializationFeaturedAdsKey($denormalizedAd->getCountryId(), $denormalizedAd->getSpecializationId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_SUBSPECIALIZATION_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySubSpecializationFeaturedAdsKey($denormalizedAd->getCountryId(), $denormalizedAd->getSubSpecializationId());
                 break;
             case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_TREATMENT_FEATURE:
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountryTreatmentFeaturedAdsKey($denormalizedAd->getCountryId(), $denormalizedAd->getTreatmentId());
                 break;
         }
     }
     $this->get('services.memcache')->delete($memcacheKey);
 }
 public function renderSearchResultsFeaturedClinicAd($params)
 {
     if (isset($params['treatmentId'])) {
         if (isset($params['cityId'])) {
             $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCityTreatmentFeaturedAdsKey($params['cityId'], $params['treatmentId']);
         } elseif (isset($params['countryId'])) {
             $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountryTreatmentFeaturedAdsKey($params['countryId'], $params['treatmentId']);
         } else {
             $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsTreatmentFeaturedAdsKey($params['treatmentId']);
         }
     } else {
         if (isset($params['subSpecializationId'])) {
             if (isset($params['cityId'])) {
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySubSpecializationFeaturedAdsKey($params['cityId'], $params['subSpecializationId']);
             } elseif (isset($params['countryId'])) {
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySubSpecializationFeaturedAdsKey($params['countryId'], $params['subSpecializationId']);
             } else {
                 $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSubSpecializationFeaturedAdsKey($params['subSpecializationId']);
             }
         } else {
             if (isset($params['specializationId'])) {
                 if (isset($params['cityId'])) {
                     $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySpecializationFeaturedAdsKey($params['cityId'], $params['specializationId']);
                 } elseif (isset($params['countryId'])) {
                     $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySpecializationFeaturedAdsKey($params['countryId'], $params['specializationId']);
                 } else {
                     $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSpecializationFeaturedAdsKey($params['specializationId']);
                 }
             }
         }
     }
     $searchResultsFeaturedClinics = $this->memcacheService->get($memcacheKey);
     if (!$searchResultsFeaturedClinics) {
         if ($ads = $this->retrieverService->getSearchResultsFeaturedClinicByCriteria($params)) {
             // https://github.com/chromedia/healthcareabroad/issues/510
             $featuredClinicIds = array();
             foreach ($ads as $ad) {
                 $featuredClinicIds[] = $ad->getInstitutionMedicalCenter()->getId();
             }
             $inSession = $this->session->get($this->getFeaturedClinicsSessionKey());
             $inSession[$this->generateSearchResultsParametersSessionKey($params)] = $featuredClinicIds;
             $this->session->set($this->getFeaturedClinicsSessionKey(), $inSession);
             $searchResultsFeaturedClinics = $this->twig->render('AdvertisementBundle:Frontend:searchResultsFeaturedAds.html.twig', array('featuredAds' => $ads));
             $this->memcacheService->set($memcacheKey, $searchResultsFeaturedClinics);
         }
     }
     return $searchResultsFeaturedClinics;
 }