?? 第一個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 + -