Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Spring Boot Start Cache Not triggering

I am running a spring boot 1.5.2 app. I wanted to add caching to my service methods I have added the spring-boot-starter-cache maven dependency and I am using the @ Cacheable annotations but it is not taking effect I created my service beans in a @ Configuration class - here is an example

@Bean(name = "policyService")
public IPolicyService policyService() {
    policyService = new PolicyServiceImpl();
    return policyService;
}

Here is an example of my service method

@Cacheable(value="policiesCache")
    public List<PolicyDBO> findAllPolicies() {
        LOG.info("Entered findAllPolicies");

        List<PolicyDBO> policyList = policyRespoitory.findAll();

        LOG.info("Exiting findAllPolicies");
        return policyList;
    }

My repoistory interface method is as follows

@Repository
public interface PolicyRepository extends CrudRepository<PolicyDBO, Long>{

    /** Find policy by id **/
    PolicyDBO findById(Long policyId);
}

Whenever I call this service method from a RestController - the caching is never triggered - it looks like it is not setup properly

Any ideas what I can do to get caching setup correctly?

Thanks Damien

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Assuming that caching is active, Spring Caching is working correctly, but not as you expect. @Cacheable caches arguments against results.

In your case, the cache is storing no arguments against the result of List<PolicyDBO>.

However when you call findById, the cache doesn't find anything against an argument of Long and so doesn't return a cached result.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda