/// <summary> /// The get short url. /// </summary> /// <param name="url">The url.</param> /// <param name="provider">The provider.</param> /// <returns> /// The <see cref="string" />. /// </returns> private string GetShortUrl(string url, IUrlShortenerProvider provider) { string shortUrl; string key = this.CreateKey(url, provider); if (this.cache.Contains(key)) { shortUrl = this.cache[key] as string; } else { shortUrl = provider.Shorten(url); var item = new CacheItem(key, shortUrl); var policy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromDays(1d) }; this.cache.Add(item, policy); } return shortUrl; }
/// <summary> /// Creates the key used to cache a result from a provider and a url. /// </summary> /// <param name="url">The URL.</param> /// <param name="provider">The provider.</param> /// <returns></returns> private string CreateKey(string url, IUrlShortenerProvider provider) { return "{0}:{1}".FormatWith(url, provider.Trigger); }