hibernate+memcached一种orm+cached解决方案

1、首先配置hibernate,使之支持二级缓存:

 

@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Teacher extends DominObject {}

 

 配置文件:

 

<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>

 

2、加入memcached配置

<!-- memercached缓存 -->
<prop key="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider</prop>
<prop key="hibernate.cache.region_prefix">quality.cache.memercached</prop>
<!-- memcached 服务地址,多个用空格分隔格式host:port-->
<prop key="hibernate.memcached.servers">10.10.7.117:11211</prop>
<!-- 缓存失效时间 -->
<prop key="hibernate.memcached.cacheTimeSeconds">300</prop>
 3、memecached的服务器安装,客户端连接需要的包看附件

你可能感兴趣的:(Hibernate)