문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
java:jpa:cache [2014/06/08 00:03] kwon37xi |
java:jpa:cache [2015/10/17 12:07] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| ====== JPA Second Level Cache ====== | ====== JPA Second Level Cache ====== | ||
| + | * [[java: | ||
| * Hibernate 4 기반으로 살펴보는 JPA2 Second Level Cache. | * Hibernate 4 기반으로 살펴보는 JPA2 Second Level Cache. | ||
| * 아직까지 살펴본바로는, | * 아직까지 살펴본바로는, | ||
| * 아래 나오는 Property Key의 대부분은 [[https:// | * 아래 나오는 Property Key의 대부분은 [[https:// | ||
| - | ===== Hibernate Cache 활성화 | + | ===== Evict All ===== |
| - | * [[java: | + | 현재 |
| - | <code sh> | + | |
| - | Map< | + | |
| - | // hibernate.cache.use_second_level_cache | + | 전체 리젼을 다 evict하려면 Hibernate의 '' |
| - | props.put(Environment.USE_SECOND_LEVEL_CACHE, | + | 관련 구현은 [[https://github.com/ |
| + | |EntityManagerFactoryImpl.java]]에 있다. | ||
| - | // hibernate.cache.use_query_cache | + | <code java> |
| - | props.put(Environment.USE_QUERY_CACHE, | + | // JPA 2.0사용시 |
| + | HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory)entityManagerFactory; | ||
| + | org.hibernate.Cache cache = hemf.getSessionFactory().getCache(); | ||
| - | // hibernate.cache.region.factory_class - 캐시 구현체 지정 | + | // JPA 2.1 사용시 |
| - | props.put(Environment.CACHE_REGION_FACTORY, | + | SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class) |
| + | org.hibernate.Cache cache = sessionFactory.getCache(); | ||
| - | // hibernate.cache.region_prefix | + | // 전체 eviction |
| - | props.put(Environment.CACHE_REGION_PREFIX, | + | cache.evictEntityRegions(); |
| - | + | cache.evictQueryRegions(); | |
| - | // hibernate.cache.default_cache_concurrency_strategy | + | cache.evictCollectionRegions(); |
| - | props.put(Environment.DEFAULT_CACHE_CONCURRENCY_STRATEGY, | + | |
| - | + | ||
| - | // ... | + | |
| - | EntityManagerFactory emf = Persistence.createEntityManagerFactory(" | + | |
| </ | </ | ||
| + | ===== 참고 ===== | ||
| + | * [[http:// | ||
| - | ===== Entity Cache ===== | ||
| - | <code java> | ||
| - | @Entity | ||
| - | @Table(name = " | ||
| - | @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE, | ||
| - | public class Book implements Serializable { | ||
| - | .... | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | ===== Query Cache ===== | ||
| - | * Query Cache는 기본적으로 region을 지정하지 않으면 '' | ||
| - | * '' | ||
| - | TypedQuery< | ||
| - | query.setParameter(" | ||
| - | |||
| - | query.setHint(" | ||
| - | query.setHint(" | ||
| - | </ | ||
| - | |||
| - | * '' | ||
| - | @Entity | ||
| - | @Table(name = " | ||
| - | @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE, | ||
| - | @NamedQuery(name = " | ||
| - | query = "from Book where edition=: | ||
| - | hints = { | ||
| - | @QueryHint(name = " | ||
| - | @QueryHint(name = " | ||
| - | } | ||
| - | ) | ||
| - | public class Book implements Serializable { | ||
| - | .... | ||
| - | } | ||
| - | </ | ||