15 Mayıs 2018 Salı

@Cache Anotasyonu

Giriş
Şu satırı dahil ederiz. İkinci seviye ön bellek içindir.
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
Şu değerleri alabilir
- ReadOnlyCache
- ReadWriteCache
- NonstrictReadWriteCache
- TransactionalCache

Açıklaması şöyle
Read-only
Useful for data that is read frequently but never updated (e.g. referential data like Countries). It is simple. It has the best performances of all (obviously).

Read/write
Desirable if your data needs to be updated. But it doesn't provide a SERIALIZABLE isolation level, phantom reads can occur (you may see at the end of a transaction something that wasn't there at the start). It has more overhead than read-only.

Nonstrict read/write
Alternatively, if it's unlikely two separate transaction threads could update the same object, you may use the nonstrict–read–write strategy. It has less overhead than read-write. This one is useful for data that are rarely updated.

Transactional
If you need a fully transactional cache. Only suitable in a JTA environment.

NONSTRICT_READ_WRITE
Örnek
Şöyle yaparız.
@Entity
@Table(...)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyAnswer implements Serializable {
  ...
}

Hiç yorum yok:

Yorum Gönder