ConsoleApp1/Services/ChuckNorrisService.cs
/// <summary>
/// Get joke categories from Web API call
/// </summary>
/// <returns></returns>
Get joke categories from Web API call
Get joke categories from Web API call
public async Task<IEnumerable<string>> GetCategoriesAsync()
        {
            try
            {
                var categories = await _memoryCache.GetOrCreateAsync<IEnumerable<string>>(CacheKeys.JokeCategories, async entry =>
                {
                    entry.SlidingExpiration = TimeSpan.FromHours(1);
                    return await Client.GetFromJsonAsync<IEnumerable<string>>(CategoryUrl);
                });
                return categories;
            }
            catch (Exception ex)
            {
                throw new ChuckNorrisServiceException(ChuckNorrisServiceException.CATEGORY_GET_ERROR, ex);
            }
        }
public async Task < IEnumerable < string > > GetCategoriesAsync ( ) { try { var categories = await _memoryCache . GetOrCreateAsync < IEnumerable < string > > ( CacheKeys . JokeCategories , async entry => { entry . SlidingExpiration = TimeSpan . FromHours ( 1 ) ; return await Client . GetFromJsonAsync < IEnumerable < string > > ( CategoryUrl ) ; } ) ; return categories ; } catch ( Exception ex ) { throw new ChuckNorrisServiceException ( ChuckNorrisServiceException . CATEGORY_GET_ERROR , ex ) ; } }
Get joke categories from Web API call
Get joke categories from Web API call
None