Shiro+springboot+mybatis+EhCache(md5+salt+散列)认证与授权-03
生活随笔
收集整理的這篇文章主要介紹了
Shiro+springboot+mybatis+EhCache(md5+salt+散列)认证与授权-03
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
從上文:Shiro+springboot+mybatis(md5+salt+散列)認證與授權-02
當每次進行刷新時,都會從數據庫重新查詢數據進行授權操作,這樣無疑給數據庫造成很大的壓力,所以需要引入緩存機制,解決頻繁訪問數據庫的壓力
使用Shiro默認的EhCache緩存進行優化
1.導入依賴
2.在攔截器中開啟緩存機制
customerRealm.setCacheManager(new EhCacheManager());customerRealm.setCachingEnabled(true);customerRealm.setAuthenticationCachingEnabled(true);customerRealm.setAuthenticationCacheName("authenticationCache");customerRealm.setAuthorizationCachingEnabled(true);customerRealm.setAuthorizationCacheName("authorizationCache");
測試:
清空日志信息
再次刷新
說明是從緩存中讀取的
每次執行都會先從緩存中查看是否有相應的數據,如果有,直接讀取出來即可,如果沒有,從數據庫讀取,然后一并放到緩存中
總結
以上是生活随笔為你收集整理的Shiro+springboot+mybatis+EhCache(md5+salt+散列)认证与授权-03的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Shiro+springboot+myb
- 下一篇: redis的基础命令操作