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

510
Visualizações
Spring Cache doesn't ignore Null key even I set the condition

In my application, the cache key is nullable, so I just wanna put it in cache when the key is not null.

I've tried a lot of different ways but it looks like Spring Cache always want a none empty key. Otherwise it throws Exception:

IllegalArgumentException: Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public com.madme.sharding.model.App com.madme.sharding.service.impl.AppServiceImpl.saveOrUpdateApp(com.madme.sharding.model.App)] caches=[appsCache] | key='#result.uuid' | keyGenerator='' | cacheManager='redisCacheManager' | cacheResolver='' | condition='' | unless='#p0.uuid == null' Ref: 1490185514616_gcfal96

I thought if I specified 'unless' condition like below, it should just ignore this CachePut without throwing any exceptions.

// I've tried #result.uuid and #p0.uuid, same output
@CachePut(value = APPS_CACHE, cacheManager = "redisCacheManager", key = "#result.uuid", unless = "#result.uuid == null")
public App saveOrUpdateApp(App app) {
    return appRepository.saveAndFlush(app);
}

Any one has any ideas?

Thanks in advance.

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

0

'condition="#p0.uuid != null"' worked... Didn't recognize that the blacklist ('unless') and whitelist ('condition') aren't checked at the same time. 'condition' is applied before key generation while 'unless' is applied after. Thank you v much @M.Deinum

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