Beispiel #1
0
        public async Task <IHttpActionResult> Get(string shortUrl)
        {
            string CachedLongurl = lruCache.Get(shortUrl);

            if (!string.IsNullOrEmpty(CachedLongurl))
            {
                return(Redirect(new System.Uri(CachedLongurl)));
            }

            string longUrl;

            try
            {
                longUrl = await database.GetLongUrlAsync(shortUrl);
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }

            lruCache.Add(shortUrl, longUrl);

            return(Redirect(new System.Uri(longUrl)));
        }