public virtual double GetTaxValue(MarketId marketId, string countryCode, string regionCode, string postalCode, string city, TaxType taxType, int?taxCategoryId) { var regionIdentifier = GetCacheRegionIdentifier(postalCode, city, regionCode, countryCode); var key = GetCacheKey <TaxValue>(marketId, regionIdentifier, taxType, taxCategoryId); if (_objectInstanceCache.Get(key) != null) { return((double)_objectInstanceCache.Get(key)); } var percentage = 0.0; if (taxCategoryId.HasValue) { var taxCategoryName = _catalogTaxManagerFacade.GetTaxCategoryNameById(taxCategoryId.Value); // TODO: refactor tax retrieval #pragma warning disable 618 var taxValues = OrderContext.Current.GetTaxes(Guid.Empty, taxCategoryName, marketId.Value, countryCode, regionCode, postalCode, null, null, city); #pragma warning restore 618 var taxValue = taxValues.FirstOrDefault(x => x.TaxType == taxType); percentage = taxValue?.Percentage ?? 0.0; } _objectInstanceCache.Insert(key, percentage, new CacheEvictionPolicy(new TimeSpan(1, 0, 0), CacheTimeoutType.Sliding)); return(percentage); }
private Guid GetOrCreateGuid(ContentReference contentLink) { string cacheKey = $"StaticContentGuid_{contentLink}"; object cachedObject = _objectInstanceCache.Get(cacheKey); if (cachedObject != null) { return((Guid)cachedObject); } var guid = Guid.NewGuid(); _objectInstanceCache.Insert(cacheKey, guid, CacheEvictionPolicy.Empty); return(guid); }
public override VirtualPathData GetVirtualPath(ContentReference contentLink, string language, VirtualPathArguments args) { if (IgnoreCache(contentLink, args)) { return(base.GetVirtualPath(contentLink, language, args)); } var cachekey = CreateCacheKey(contentLink, language, args); var value = _cache.Get(cachekey) as VirtualPathData; if (value == null) { value = base.GetVirtualPath(contentLink, language, args); if (value != null) { _cache.Insert(cachekey, value, CreateCacheEvictionPolicy()); } } return(value); }