# 23. CacheManager 緩存管理
# 23. CacheManager 緩存管理
Shiro 有三個重要的緩存接口:
- [CacheManager](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/cache/CacheManager.html) - 負責所有緩存的主要管理組件,它返回 Cache 實例。
- [Cache](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/cache/Cache.html) - 維護key/value 對。
- [CacheManagerAware](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/cache/CacheManagerAware.html) - 通過想要接收和使用 CacheManager 實例的組件來實現。
CacheManager 返回Cache 實例,各種不同的 Shiro 組件使用這些Cache 實例來緩存必要的數據。任何實現了 CacheManagerAware 的 Shiro 組件將會自動地接收一個配置好的 CacheManager,該 CacheManager 能夠用來獲取 Cache 實例。
Shiro 的 [SecurityManager](http://shiro.apache.org/securitymanager.html) 實現及所有 [AuthorizingRealm](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/realm/AuthenticatingRealm.html) 實現都實現了 CacheManagerAware 。如果你在 SecurityManager 上設置了 CacheManger,它反過來也會將它設置到實現了CacheManagerAware 的各種不同的 Realm 上(OO delegation)。例如,在 shiro.ini 中:
```
securityManager.realms = $myRealm1, $myRealm2, ..., $myRealmN
...
cacheManager = my.implementation.of.CacheManager
...
securityManager.cacheManager = $cacheManager
# at this point, the securityManager and all CacheManagerAware
# realms have been set with the cacheManager instance
```
我們有開箱即用的 [EhCacheManager](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/cache/ehcache/EhCacheManager.html)實現 ,所以馬上就能使用它。否則,您也可以很好的實現自己的 CacheManager (例如 Coherence,等),配置如上。
## Authorization Cache Invalidation 授權緩存失效
最后請注意, [AuthorizingRealm](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/realm/AuthorizingRealm.html) 有一個 [clearCachedAuthorizationInfo](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/realm/AuthorizingRealm.html#clearCachedAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)) 方法能夠被子類調用,用來清除特殊賬戶緩存的授權信息。它通常被自定義邏輯調用,如果與之匹配的賬戶授權數據發生了改變(來確保下次的授權檢查能夠捕獲新數據)。
## 為文檔加把手
我們希望這篇文檔可以幫助你使用 Apache Shiro 進行工作,社區一直在不斷地完善和擴展文檔,如果你希望幫助 Shiro 項目,請在你認為需要的地方考慮更正、擴展或添加文檔,你提供的任何點滴幫助都將擴充社區并且提升 Shiro。
提供你的文檔的最簡單的途徑是將它發送到用戶[論壇](http://shiro-user.582556.n2.nabble.com/)或[郵件列表](http://shiro.apache.org/mailing-lists.html)
*譯者注:*如果對本中文翻譯有疑議的或發現勘誤歡迎指正,[點此](https://github.com/waylau/apache-shiro-1.2.x-reference/issues)提問。
- Introduction
- 1. Introduction 介紹
- 2. Tutorial 教程
- 3. Architecture 架構
- 4. Configuration 配置
- 5. Authentication 認證
- 6. Authorization 授權
- 6.1. Permissions 權限
- 7. Realms
- 8. Session Management
- 9. Cryptography 密碼
- 10. Web
- 10.1. Configuration 配置
- 10.2. 基于路徑的 url 安全
- 10.3. Default Filters 默認過濾器
- 10.4. Session Management
- 10.5. JSP Tag Library
- 11. Caching 緩存
- 12. Concurrency & Multithreading 并發與多線程
- 13. Testing 測試
- 14. Custom Subjects 自定義 Subject
- 15. Spring Framework
- 16. Guice
- 17. CAS
- 18. Command Line Hasher
- 19. Terminology 術語
- 20. 10 Minute Tutorial 十分鐘教程
- 21. Beginner's Webapp Tutorial 初學者web應用教程
- 22. Application Security With Apache Shiro 用Shiro保護你的應用安全
- 23. CacheManager 緩存管理
- 24. Apache Shiro Cryptography Features 加密功能