blob: 0bc86720f4fe9b2f35cad98d2e40220cb52d628f [file] [log] [blame]
<p>Shiro has three important cache interfaces:</p>
<ul><li><tt><a class="external-link" href="static/current/apidocs/org/apache/shiro/cache/CacheManager.html">CacheManager</a></tt></li><li><tt><a class="external-link" href="static/current/apidocs/org/apache/shiro/cache/Cache.html">Cache</a></tt></li><li><tt><a class="external-link" href="static/current/apidocs/org/apache/shiro/cache/CacheManagerAware.html">CacheManagerAware</a></tt></li></ul>
<p>A <tt>CacheManager</tt> returns <tt>Cache</tt> instances and various Shiro components use those <tt>Cache</tt> instances to cache data as necessary. Any Shiro<br clear="none">
component that implements <tt>CacheManager</tt> will automatically receive a configured <tt>CacheManager</tt>, where it can be used to acquire <tt>Cache</tt> instances.</p>
<p>The Shiro <a href="securitymanager.html" title="SecurityManager">SecurityManager</a> implementations and all <tt><a class="external-link" href="static/current/apidocs/org/apache/shiro/realm/AuthorizingRealm.html">AuthorizingRealm</a></tt> implementations implement CacheManagerAware. If you set the <tt>CacheManager</tt> on the <tt>SecurityManager</tt>, it will in turn set it on the various Realms that implement CacheManagerAware as well (OO delegation). For example, in shiro.ini:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>example shiro.ini CacheManger configuration</b></div><div class="codeContent panelContent">
<pre class="code-java">
securityManager.realms = $myRealm1, $myRealm2, ..., $myRealmN
...
cacheManager = my.implementation.of.CacheManager
...
securityManager.cacheManager = $cacheManager
# at <span class="code-keyword">this</span> point, the securityManager and all CacheManagerAware
# realms have been set with the cacheManager instance
</pre>
</div></div>
<p>We have an out-of-the-box <tt><a class="external-link" href="static/current/apidocs/org/apache/shiro/cache/ehcache/EhCacheManager.html">EhCacheManager</a></tt> implementation, so you can use that today if you wanted. Otherwise, you can implement your own <tt>CacheManager</tt> (e.g. with Coherence, etc) and configure it as above, and you'll be good to go.</p>
<h3><a name="CacheManager-AuthorizationCacheInvalidation"></a>Authorization Cache Invalidation</h3>
<p>Finally note that <tt><a class="external-link" href="static/current/apidocs/org/apache/shiro/realm/AuthorizingRealm.html">AuthorizingRealm</a></tt> has a {{<a class="external-link" href="static/current/apidocs/org/apache/shiro/realm/AuthorizingRealm.html#clearCachedAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)">clearCachedAuthorizationInfo method</a> that can be called by subclasses to evict the cached authzInfo for a particular account. It is usually called by custom logic if the corresponding account's authz data has changed (to ensure the next authz check will pick up the new data).</p>
<h2><a name="CacheManager-Lendahandwithdocumentation"></a>Lend a hand with documentation </h2>
<p>While we hope this documentation helps you with the work you're doing with Apache Shiro, the community is improving and expanding the documentation all the time. If you'd like to help the Shiro project, please consider corrected, expanding, or adding documentation where you see a need. Every little bit of help you provide expands the community and in turn improves Shiro. </p>
<p>The easiest way to contribute your documentation is to send it to the <a class="external-link" href="http://shiro-user.582556.n2.nabble.com/" rel="nofollow">User Forum</a> or the <a href="mailing-lists.html" title="Mailing Lists">User Mailing List</a>.</p>