当前位置:网站首页>Initial experience of cache and ehcache "suggestions collection"
Initial experience of cache and ehcache "suggestions collection"
2022-07-07 19:08:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
1. The meaning of caching
The caching mechanism is to take out the data often used in the database and put it into memory . When the program is called, it fetches directly from memory , Use every time Data access database , This improves efficiency .
2. Caching needs attention
1) Cache update
The data in the cache must be consistent with the data in the database .
2) Cache hit rate
Improve the utilization of cached data , The cache stores data that users often use , Suppose that the cache stores something that users don't often use . Then the hit rate of cache is not high . Sometimes , It is the high utilization rate of some cached data at a certain time , Low utilization at a certain time , So it needs to be updated constantly , To improve cache hit ratio .
Hibernate Cache mechanism
• The first level cache is Session The cache of . because Session The life cycle of an object usually corresponds to a database transaction or an application transaction , So its cache is a transaction wide cache . First level caching is necessary , Disagree and can't be removed . In the first level cache . Each instance of a persistent class has a unique OID. • The second level cache is a pluggable cache plug-in , It consists of SessionFactory Responsible for managing the . because SessionFactory The life cycle of the object corresponds to the whole process of the application , So the second level cache is Process wide cache . This cache stores the bulk data of the object .
The second level cache is optional . The second level cache can be configured on the granularity of each class or collection .
remarks :
L1 cache may cause repeated data queries , thus , We introduced the second level cache mechanism .
The first level cache is used by user threads . The L2 cache is shared by everyone .
What we need to learn is how to control the L2 cache , To this end, we need to ensure 2 spot :
1). How to update the data in the L2 cache Suppose the user does not change the data of the database , We need to update the cache immediately 2). Ensure the hit rate of data in L2 cache Change space for time .
Data in L2 cache
When necessary, we use frequent data .
3.EhCache
1. Brief introduction
EhCache It's pure. Java In process caching framework for . With high speed 、 Characteristics such as ability . yes Hibernate In the default CacheProvider.
2. stay Hibernate Use in EhCache
Change profile Hibernate.cfg.xml
<property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>3. The configuration file ehcache.xml
The meanings of parameters are • maxElementInMemory Indicates how many objects can be placed in the cache , Here is 10000 individual , It can be configured according to the amount of memory • eternal Indicates whether to set these data objects put into the L2 cache to be permanent ( Put it in and save it . No longer clear ) Typically for false • timeToIdleSeconds=120 It is assumed that 120 Seconds . The placed object is not accessed again , Just clear it out • timeToLiveSeconds=120 Indicates the time the object survives in the cache , An object enters this cache 120 Seconds later , It will be cleared away by itself ( Generally, the setting time will be longer than timeToIdleSeconds Long time ).
This property is set to allow many other active objects to enter From cache . • overflowToDisk=”true” Indicates that the assumed active object has exceeded maxElementInMemory Set the maximum value of , Exceeded objects are written Save it on your hard disk . Ease the situation with more active users .
4. Change the detailed mapping file xxx.hbm.xml
Join the familiar :<property region=”default” usage=”read-write”>
• region attribute Indicates which L2 cache to use • usage attribute Indicates how L2 cache is used There are two kinds of :read-only and read-write read-only Let's say it's read-only. Then it cannot be changed . such ehcache There is no need to consider the operation of changes and updates . read-write Set to read-write,ehcache Also consider updates and changes . This will reduce efficiency .
therefore . Set up usage Attributes are very important , It is necessary to infer that the stored objects use L2 cache based on the actual situation .
Welcome to discuss and study together !
Practical self collection !
Record and share . Let us grow together ! Welcome to my other blogs . My blog address :http://blog.csdn.net/caicongyang
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116611.html Link to the original text :https://javaforall.cn
边栏推荐
- 高考填志愿规则
- The moveposition function of rigidbody2d of unity2d solves the problem of people or screen jitter when moving
- GSAP animation library
- UVALive – 4621 Cav 贪心 + 分析「建议收藏」
- App capture of charles+postern
- Redis publishing and subscription
- 国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
- How many times is PTA 1101 B than a
- CVPR 2022丨学习用于小样本语义分割的非目标知识
- Usage of PHP interview questions foreach ($arr as $value) and foreach ($arr as $value)
猜你喜欢

數據驗證框架 Apache BVal 再使用

The top of slashdata developer tool is up to you!!!

Static routing configuration
![[tpm2.0 principle and Application guide] Chapter 9, 10 and 11](/img/7f/0d4d91142bc3d79ea445a8f64afba7.png)
[tpm2.0 principle and Application guide] Chapter 9, 10 and 11

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
![[tpm2.0 principle and Application guide] Chapter 16, 17 and 18](/img/7a/b16549590e6445d9199c8000d47d36.png)
[tpm2.0 principle and Application guide] Chapter 16, 17 and 18

伺服力矩控制模式下的力矩目标值(fTorque)计算

6. About JWT

Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
随机推荐
2022-07-04 matlab读取视频帧并保存
Reuse of data validation framework Apache bval
Tsinghua, Cambridge and UIC jointly launched the first Chinese fact verification data set: evidence-based, covering many fields such as medical society
静态路由配置
脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
Thread pool and singleton mode and file operation
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
手把手教姐姐写消息队列
Thread factory in thread pool
99% of people don't know that privatized deployment is also a permanently free instant messaging software!
How much does it cost to develop a small program mall?
Calculation of torque target value (ftorque) in servo torque control mode
What is the general yield of financial products in 2022?
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
Standard ACL and extended ACL
[sword finger offer] 59 - I. maximum value of sliding window
Big Ben (Lua)
Redis集群与扩展
Skills of embedded C language program debugging and macro use