본문 바로가기

Programming!

JPA EhCache 사용.

이전에는 redis나 memcached에 일반 엔티티들도 우걱우걱 밀어넣었는데, 네트웍 과부하 문제나 불필요한 트래픽 문제를 겪고 나서는 그냥 가벼운 엔티티 호출의 경우는 로컬 ehcache에서 읽어오도록 하고 있다.

@Cacheable

@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Goods {
...


  • 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.