Shiro combat series (11): caching

The Shiro development team understands that performance is critical in many applications. Caching is the first state-of-the-art feature built in Shiro from day one to ensure that secure operations remain as fast as possible. However, as a concept, caching is a basic part of Shiro. Implementing a complete caching mechanism is beyond the core competence of the security framework. Therefore, Shiro's cache support is basically an abstract (wrapper) API, which will "sit" on a basic cache mechanism product (e.g., ehcache, OSCache, terracotta, coherence, gigaspaces, JBossCache, etc.). This allows Shiro end users to configure any cache mechanism they like.

(1) Caching API Shiro has three important caching interfaces: CacheManager - the main management component responsible for all caches, which returns cache instances.

(2) Cache - maintain key / value pairs.

(3) Cachemanageraware - implemented by components that want to receive and use CacheManager instances. CacheManager returns cache instances, which are used by various Shiro components to cache necessary data. Any Shiro component that implements cachemanageraware will automatically receive a configured CacheManager that can be used to obtain cache instances.

Shiro's securitymanager implementation and all authoringrealm implementations implement cachemanageraware. If you set CacheManager on securitymanager, it will also set it to different realms (OO delegation) that implement cachemanageraware. For example, in shiro.ini:

We have an immediate implementation of ehcachemanager, so you can use it today if you want. On the contrary, you can implement your own CacheManager (such as using coherence) and configure it as above, and you will achieve good results.

Authorization Cache Invalidation

Finally, please note that authorizingrealm has a clearcachedauthorizationinfo method that can be called by subclasses to clear the authorization information cached by special accounts. It is usually called by custom logic. If the matching account authorization data changes (to ensure that the next authorization check can capture new data).

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>