Esempio n. 1
0
 public PokemonsCacheService(
     IMemoryCache memoryCache,
     ILogger <PokemonsCacheService> logger,
     IPokemonsService pokemonsService)
 {
     _memoryCache     = memoryCache;
     _logger          = logger;
     _pokemonsService = pokemonsService;
     _typeName        = GetType().Name;
 }
Esempio n. 2
0
        public async Task <DTO.FullPokemon> Get(int id, [FromServices] IPokemonsService service,
                                                [FromServices] IMemoryCache cache)
        {
            var pokemon = cache.Get <DTO.FullPokemon>($"GetPokemon{id}");

            if (pokemon != null)
            {
                return(pokemon);
            }

            pokemon = await service.Get(id);

            cache.Set($"GetPokemon{id}", pokemon);

            return(pokemon);
        }
Esempio n. 3
0
        public async Task <List <DTO.EvolutionChainPokemon> > GetEvolutionChain(int id,
                                                                                [FromServices] IPokemonsService service, [FromServices] IMemoryCache cache)
        {
            var evolutionChain = cache.Get <List <DTO.EvolutionChainPokemon> >($"EvolutionChain{id}");

            if (evolutionChain != null)
            {
                return(evolutionChain);
            }

            evolutionChain = await service.GetEvolutionChain(id);

            cache.Set($"EvolutionChain{id}", evolutionChain);

            return(evolutionChain);
        }
Esempio n. 4
0
 public async Task <DTO.PokemonStats> GetMaxStats([FromServices] IPokemonsService service)
 {
     return(await service.GetMaxStats());
 }
Esempio n. 5
0
 public async Task <List <DTO.PokemonList> > GetAll([FromServices] IPokemonsService service)
 {
     return(await service.GetAll());
 }