Giriş
@Cacheable ile cache'lenen veriyi temizler.
@Cacheable ile cache'lenen veriyi temizler.
Örnek
Şöyle yaparız.
Şöyle yaparız.
@Cacheable(value=Constants.CATEGORYCACHE)
public List<Category> getCategoryList(Category category) {
  return categoryDAO.getCategoryList(category);
}
@CacheEvict(value=Constants.CATEGORYCACHE)
public void deleteCategory(Category category) {
  categoryDAO.deleteCategory(category);
}Örnek
 Bu anotasyon tek başına kullanılacağı gibi @Caching içinde de kullanılabilir. Şöyle yaparız.
@Caching(evict = {
    @CacheEvict("primary"),
    @CacheEvict(value = "secondary", key = "#p0")
})allEntries Alanı
Belirtilen bir key için değil de her şeyi silmek için kullanılır
Örnek
Şöyle yaparız
@CacheEvict(value="addresses", allEntries=true)
public void clearAddresses() {
}Örnek
Şöyle yaparız. saveOrUpdate() işlemi olunca tüm cache'leri temizleyip daha sonra getAllPersons() ile cache tekrar dolduruluyor. Bence çok iyi bir kullanım değil. Sadece örnek olsun diye aldım
@CacheEvict(allEntries = true) 
public void saveOrUpdate(Person person) {
     personRepository.save(person);
}
// caches the result of getAllPersons() method
@Cacheable 
public List<Person> getAllPersons()  {
  return personRepository.findAll();
}Örnek
Şöyle yaparız.
Örnek
Şöyle yaparız.
Şöyle yaparız.
cacheNames ile alias'tır yani aynıdır.
Örnek
Belli aralıklarla Cache'i temizlemek için şöyle yaparız.
@CacheEvict(cacheNames = "CACHE_NAME_COUPONS_TYPES", allEntries = true)
public void clearCouponsTypesCache() {
}Örnek
Şöyle yaparız.
@CacheEvict(allEntries = true, cacheNames = { "cache_1", "cache_2" })
@Scheduled(fixedDelay = 30000)
public void cacheEvict() {
}Şöyle yaparız.
@CacheEvict(value = "secondary", key = "#p0")cacheNames ile alias'tır yani aynıdır.
Örnek
Belli aralıklarla Cache'i temizlemek için şöyle yaparız.
@Scheduled(cron = "${YOUR_CRON_INTERVAL}")
@CacheEvict(value = "yourCache", allEntries = true)
public void resetAllEntries() {
    //write the code to repopulate the cache again here
}
 
Hiç yorum yok:
Yorum Gönder