Giriş
Açıklaması şöyle
Açıklaması şöyle
It is a method level annotation. It is used to update the cache before invoking the method. By doing this, the result is put in the cache and the method is executed. It has same attributes of @Cacheable annotation.
Açıklaması şöyle.
@Cacheable ile farkının açıklaması şöyle.CachePut annotation does not cause the target method to be skipped - rather it always causes the method to be invoked and its result to be placed into the cache.
@CachePut always lets the method execute. It is generally used if you want your cache to be updated with the result of the method execution.
Example: When you want to update a stale data which is cached, instead of blowing the cache completely.
@Cacheable will be executed only once for the given cachekey and subsequent requests won't execute the method, until the cache expires or gets flushed.
condition Alanı
Örnek
Şöyle yaparız
@CachePut(value="addresses", condition="#customer.name=='Tom'")
public String getAddress(Customer customer) {
return "Adresses";
}
Örnek
Şöyle yaparız.
@CachePut(value = "user", key = "#user.id")
public User createUser(User user) {
// store user in db...
}
unless Alanı
Örnek
Şöyle yaparız. 64 karakterden uzun sonuçları cache'e koyar
@CachePut(value="addresses", unless="#result.length()<64")
public String getAddress(Customer customer) {
return "Adresses";
}
value Alanı
Örnek
Şöyle yaparız
@CachePut(value="employee")
public Employee updateEmployee(Employee employee) {
// some code
}
Hiç yorum yok:
Yorum Gönder