JEECMS3.2-final 学习笔记

JEECMS3.2-final 学习笔记
一、启动:
二、缓存:
缓存是通过Encache来实现的,Encache主页 http://ehcache.org/,指引文档: http://ehcache.org/EhcacheUserGuide.html
1.定义encache配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd">
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="30"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
	<cache name="com.jeecms.core.page.Homepage"
		maxElementsInMemory="3" 
                  eternal="false" 
                  timeToIdleSeconds="7200" 
                  timeToLiveSeconds="8640"
		overflowToDisk="true" 
                  diskSpoolBufferSizeMB="30" 
                  maxElementsOnDisk="30" 
                  diskPersistent="true"
	/>
	<cache name="com.jeecms.core.page.Channel"
		maxElementsInMemory="20" 
                  eternal="false" 
                  timeToIdleSeconds="7200" 
                  timeToLiveSeconds="8640"
		overflowToDisk="true" 
                  diskSpoolBufferSizeMB="30" 
                  maxElementsOnDisk="200" 
                  diskPersistent="true"
	/>
            
	<cache name="com.jeecms.core.entity.Website.DOMAIN2ID" 
		maxElementsInMemory="3000"
		eternal="true"
		overflowToDisk="true" 
		/>
	<cache name="com.jeecms.core.entity.Website.Alias2DOMAIN" 
		maxElementsInMemory="10000"
		eternal="true"
		overflowToDisk="true" 
		/>
	<cache name="com.jeecms.core.entity.User.LOGINNAME2ID" 
		maxElementsInMemory="3000"
		eternal="false"
		timeToIdleSeconds="3600"
		timeToLiveSeconds="7200"
		overflowToDisk="false"
		/>
	<cache name="com.jeecms.core.CommonId" 
		maxElementsInMemory="10000"
		eternal="false"
		timeToIdleSeconds="3600"
		timeToLiveSeconds="7200"
		overflowToDisk="false"
		/>
</ehcache>


2.与spring整合:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
	>
	<!--缓存-->
	<bean id="cacheManager"         class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">    
		<property name="configLocation">
			<value>classpath:ehcache-application.xml</value>
		</property>
		<!--
			<property name="shared">
			  <value>true</value>
			</property>
			-->
	</bean>
	<!--首页缓存-->
	<bean id="homepageCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager"/>
		</property>
		<property name="cacheName">
			<value>com.jeecms.core.page.Homepage</value>
		</property>
		<qualifier value="homepage"/>
	</bean>
	<!--栏目页缓存-->
	<bean id="channelCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager"/>
		</property>
		<property name="cacheName">
			<value>com.jeecms.core.page.Channel</value>
		</property>
		<qualifier value="channel"/>
	</bean>
	<!--域名缓存-->
	<bean id="websiteDomainCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager"/>
		</property>
		<property name="cacheName">
			<value>com.jeecms.core.entity.Website.DOMAIN2ID</value>
		</property>
		<!-- 指定注入bean的名称 -->
		<qualifier value="websiteDomain"/>
	</bean>
	<!--域名别名缓存-->
	<bean id="websiteAliasCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager"/>
		</property>
		<property name="cacheName">
			<value>com.jeecms.core.entity.Website.Alias2DOMAIN</value>
		</property>
		<qualifier value="websiteAlias"/>
	</bean>
	<!--统一用户登录名缓存-->
	<bean id="userLoginNameCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager"/>
		</property>
		<property name="cacheName">
			<value>com.jeecms.core.entity.User.LOGINNAME2ID</value>
		</property>
		<qualifier value="userLoginName"/>
	</bean>
	<!--通用ID缓存-->
	<bean id="commonIdCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager"/>
		</property>
		<property name="cacheName">
			<value>com.jeecms.core.CommonId</value>
		</property>
		<qualifier value="commonId"/>
	</bean>
 
</beans>



3.注入到service
@Service
public class HomepageCacheSvcImpl implements HomepageCacheSvc {
	public void put(Serializable key, byte[] bytes) {
		homepageCache.put(new Element(key, bytes));
	}

	public byte[] get(Serializable key) {
		Element e = homepageCache.get(key);
		if (e != null) {
			return (byte[]) e.getValue();
		} else {
			return null;
		}
	}

	public boolean remove(Long webId) {
		return homepageCache.remove(webId);
	}

	@Autowired
	public void setHomepageCache(@Qualifier("homepage") Cache homepageCache) {
		this.homepageCache = homepageCache;
	}

	private Cache homepageCache;
}

你可能感兴趣的:(spring,html,xml,bean,cache)