📄 第一个acegi 程式 - 使用user cache.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0076)http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/FirstAcegiUserCache.html -->
<HTML><HEAD><TITLE>第一个Acegi 程式 - 使用User Cache</TITLE><LINK
href="第一个Acegi 程式 - 使用User Cache.files/stdlayout.css" type=text/css
rel=stylesheet><LINK href="第一个Acegi 程式 - 使用User Cache.files/print.css"
type=text/css rel=stylesheet>
<META http-equiv=content-type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY>
<H3><A
href="http://caterpillar.onlyfun.net/GossipCN/index.html">http://caterpillar.onlyfun.net/GossipCN/index.html</A></H3>
<H1><A
href="http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/AcegiGossip.html">Acegi
Gossip: 第一个Acegi 程式 - 使用User
Cache</A></H1>如果考虑到效能的问题,当从资料库中撷取资料出来时,您会想到捞出来的资料是不是可以重复使用,不用每一次都连接资料库进行查询。<BR><BR>Acegi可以使用User
Cache,当AuthenticationProvider需要使用者资料时,先行至User
Cache中寻找是否有符合的项目,有的话就直接取回比对,没有的话,再从资料库或其它资料来源取得,这可以修改 <A
href="http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/FirstAcegiFromDB.html">第一个Acegi
程式 - 改用资料库作为验证来源 </A>作为示范,只要修改一下daoAuthenticationProvider 的设定,并加入User
Cache即可:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
...</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<bean id="daoAuthenticationProvider"
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="userDetailsService" ref="jdbcDaoImpl"/></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<property name="userCache" ref="userCache"/></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</bean> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<bean id="jdbcDaoImpl"
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
<property name="dataSource" ref="dataSource"/></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</bean> </SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
</SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<bean id="userCache"
class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache"></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<property name="cache"></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<bean
class="org.springframework.cache.ehcache.EhCacheFactoryBean"></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<property name="cacheManager"></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
/></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
</property></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
<property name="cacheName" value="userCache" /></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
</bean></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
</property></SPAN><BR
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">
</bean></SPAN><BR
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">
...</SPAN><BR></DIV><BR>现在您可以重新启动程式,当查询到使用者资料时,会将之放入快取,之后若有相同的查询,会先至快取中查询有无资料。<BR><BR>由于使用了EhCache,所以别忘了加入ehcache-*.jar与相依的commons-collections-*.jar。<BR><BR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -