Je souhaite mettre en cache certaines tables de base de données dans mon application car le contenu des tables n'est mis à jour qu'une fois par jour.Spring Cache - Cache uniquement certaines tables
J'ai obtenu Spring Cache à travailler comme ceci:
@Service("stuffManager")
public class StuffManagerImpl implements StuffManager {
@Autowired
private StuffDao stuffDao;
@Override
@Cacheable("stuffCache")
public List<Stuff> getAllStuff() {
return stuffDao.getAllStuff();
}
}
@Repository("stuffDao")
public class StuffDaoHibernate implements StuffDao {
@Override
public List<Stuff> getAllStuff() {
return getHQLResult("select* from Stuff", null);
}
}
Mais est-il possible d'utiliser Spring Cache si mon getAllStuff
-method ressemblait à cela, mais je voulais seulement mettre en cache la Stuff
-table?
@Repository("stuffDao")
public class StuffDaoHibernate implements StuffDao {
@Override
public List<Stuff> getAllStuff() {
return getHQLResult("select Stuff.* from Stuff inner join OtherStuff on Stuff.Id = OtherStuff.Id", null);
}
}
1.Votre méthode annotée avec @Cacheable annotation est supposée avoir des arguments de méthode, de sorte que vous pouvez récupérer la prochaine fois avec la valeur arg comme clé 2. Le cache Spring fournit une abstraction pour stocker l'objet java dans le cache sous-jacent. C'est vous, comment vous peuplez votre objet java. –
@AmitParashar Pourriez-vous clarifier comment cela pourrait résoudre mon problème? – user1766169