In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use Shiro performance optimization EhCache, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
* evict: expel, expel
Ps: after using shiro for permission management, you need to call realm to query roles and permissions every time, and you need to check the database every time. The performance is not very good.
Pps: can the data in the database be cached to reduce database interaction and improve performance?
One: why do you use ehcache instead of redis cache in technology selection?
Shiro default support for ehcache
Ehcache is widely used in background management system.
2: spring integrates ehcache (1) maven depends on net.sf.ehcache ehcache-core 2.6.11 org.springframework spring-context-support 4.2.8.RELEASE (2) Import ehcache.xml configuration file
Extract the ehcache-core.jar package and rename the ehcache-failsafe.xml copy src/main/resources to ehcache.xml
Default cache area
You can customize the cache (write by default if you don't want to change it)
(3) hand over EhCache to Spring for management
3: shiro integrates ehcache (1) configure the cache manager of shiro to encapsulate ehcache
(2) inject the cache manager of shiro into the security manager. (3) specify the cache area for authentication and authorization data.
Note: objects that need to be cached should implement the serializable interface
Four: cache declaration
Spring provides a set of annotations for integrating buffers
Turn on comment caching
(1) @ CacheEvict
Clear the cache, usually after the database data changes, clear the cache, such as add, delete
@ Override@CacheEvict (value= "myCache", allEntries=true) public void save (User user) {userDao.save (user);} (II) @ Cacheable ("cache name")
Cached after query
1. Cache the return value of the no-parameter method @ Override@Cacheable ("myCache") public List findAll () {return userDao.findAll ();} 2. Cache the return value of the parameter method
For data caching under different conditions, we can specify the cached key, support object nesting, and support spel expressions.
@ Override@Cacheable (value= "myCache", key= "# pageable.pageNumber+'_'+#pageable.pageSize") public List findPageData (Pageable pageable) {return userDao.findAll (pageable);} the above is how to use Shiro to optimize EhCache performance. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.