⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第一个acegi 程式 - 使用user cache.htm

📁 acegi+spring最新的分析
💻 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:&nbsp;第一个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">&nbsp; 
&nbsp;...</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;bean id="daoAuthenticationProvider" 
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="userDetailsService" ref="jdbcDaoImpl"/&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="userCache" ref="userCache"/&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;/bean&gt; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;bean id="jdbcDaoImpl" 
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="dataSource" ref="dataSource"/&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
&lt;/bean&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp; 
</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">&nbsp;&nbsp;&nbsp; 
&lt;bean id="userCache" 
class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache"&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="cache"&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;bean 
class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="cacheManager"&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
/&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/property&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="cacheName" value="userCache" /&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/bean&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/property&gt;</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">&nbsp;&nbsp;&nbsp; 
&lt;/bean&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp; 
&nbsp;...</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 + -