Ejemplo n.º 1
0
 public Task <long> GetNextIdAsync(string url)
 {
     return(_Cache.GetOrCreateAsync(url, entry =>
     {
         entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1);
         return _RealGenerator.GetNextIdAsync(url);
     }));
 }
        /// <inheritdoc />
        public async Task <string> ShortenAsync(string originalLink)
        {
            if (string.IsNullOrWhiteSpace(originalLink))
            {
                throw new UrlIsMissingException($"Url is required");
            }

            if (!_UrlValidator.IsValid(originalLink))
            {
                throw new UrlIsInvalidException($"Url \'{originalLink}\' have incorrect format");
            }

            var id = await _LinksIdGenerator.GetNextIdAsync(originalLink);

            return(ToBase62(id));
        }