/// <summary> /// Retrieve a Cache Info object from the CacheType and CacheDuration, if present. /// </summary> /// <param name="dc">Dialog Context to use for retrieving CacheType and CacheDuration from state.</param> /// <returns>A <see cref="CacheInfo"/> object if <see cref="CacheDuration"/> /// and <see cref="CacheType"/> resolve to valid values.</returns> protected CacheInfo GetCacheInfo(DialogContext dc) { if (CacheType != null && CacheDuration != null) { var cacheType = CacheType.GetValueOrNull(dc.State); var cacheDuration = CacheDuration.GetValueOrNull(dc.State); if (cacheDuration.HasValue && cacheDuration.Value > 0 && !string.IsNullOrEmpty(cacheType)) { // Valid ranges for CacheDuration are 60 < > 2592000 cacheDuration = Math.Min(Math.Max(60, cacheDuration.Value), 2592000); return(new CacheInfo(cacheType: cacheType, cacheDuration: cacheDuration.Value)); } } return(null); }