Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
Schedule Spring cache eviction?

Is it possible to schedule spring cache eviction to everyday at midnight?

I've read Springs Cache Docs and found nothing about scheduled cache eviction.

I need to evict cache daily and recache it in case there were some changes outside my application.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Try to use @Scheduled Example:

@Scheduled(fixedRate = ONE_DAY)
@CacheEvict(value = { CACHE_NAME })
public void clearCache() {  
    log.debug("Cache '{}' cleared.", CACHE);    
}

You can also use cron expression with @Scheduled.

about 4 years ago · Santiago Trujillo Denunciar

0

If you use @Cacheable on methods with parameters, you should NEVER forget the allEntries=true annotation property on the @CacheEvict, otherwise your call will only evict the key parameter you give to the clearCache() method, which is nothing => you will not evict anything from the cache.

about 4 years ago · Santiago Trujillo Denunciar

0

Maybe not the most elegant solution, but @CacheEvict was not working, so I directly went for the CacheManager.

This code clears a cache called foo via scheduler:

class MyClass {

    @Autowired CacheManager cacheManager;

    @Cacheable(value = "foo")
    public Int expensiveCalculation(String bar) {
        ...
    }

    @Scheduled(fixedRate = 60 * 1000);
    public void clearCache() {
        cacheManager.getCache("foo").clear();
    }
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda