Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Spring almacenable en caché con objeto

Puedo hacer lo siguiente mientras uso Cacheable:

 @Cacheable(value = CacheUtil.LEVEL1, key = "'Location'+#root.methodName+'_'+#country+'_'+#lang") public List<Location> getCities(String country, String lang)

y funciona bien

Aunque no estoy seguro de lo siguiente. ¿Cómo puedo almacenar en caché el siguiente método con Cacheable?

 public Content getContent(ContentRequest Request)

¿Cómo debo escribir el @Cacheable para que funcione?

Gracias.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Necesitas algo como esto:

 @Cacheable(value = CacheUtil.LEVEL1, keyGenerator="contentRequestKeyGenerator") public Content getContent(ContentRequest Request)

Donde contentRequestKeyGenerator es el nombre de un bean que implementa la interfaz KeyGenerator, consulte http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/interceptor/KeyGenerator.html

En el pasado, tuve un bean que genera claves para varias clases de caché diferentes, en el siguiente ejemplo, los objetos [0] son la clase del método de llamada, ContentRequest en su ejemplo:

 @Component public class MyKeyGenerator implements KeyGenerator{ @Override public Object generate(Object o, Method method, Object... objects) { if (String.class.isInstance(objects[0])) { return .... } else if (....) { } }

Entonces usarías esto:

 @Cacheable(value = "properties", keyGenerator = "myKeyGenerator") public Property getProperty(String key) {

¿Necesitas hacer esto? El valor predeterminado es el código hash de ContentRequest, por lo general esto es lo suficientemente bueno.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!