How to clean up or close the second-level cache

As long as this article is about how to clean up or turn off the second-level cache, I hope this article can give you a deeper understanding of the second-level cache.

Secondary cache

The CPU cache (Cache Memory) is a temporary storage between the CPU and the memory. Its capacity is smaller than the memory but the exchange speed is faster. The data in the cache is a small part of the memory, but this small part is about to be accessed by the CPU in a short time. When the CPU calls a large amount of data, it can avoid the memory and call it directly from the cache, thereby speeding up the reading speed. . Initially, the cache was only level one, and the second level cache (L2 CACHE) appeared to coordinate the speed between the level one cache and the memory. The second-level cache is slower than the first-level cache and has a larger capacity. It is mainly used for temporary exchange of data between the first-level cache and the memory. In fact, Intel and AMD processors are different in the logical structure design of the first level cache, so the impact of the second level cache on the CPU performance is also different.

working principle

The working principle of the cache is that when the CPU wants to read a piece of data, it first looks it up in the cache, if it finds it, it reads it immediately and sends it to the CPU for processing; if it doesn’t find it, it reads it from the memory and sends it to it at a relatively slow speed. CPU processing, and at the same time transfer the data block where this data is located into the cache, so that the entire block of data can be read from the cache in the future, without having to call the memory.

It is this read mechanism that makes the CPU read cache hit rate very high (most CPUs can reach about 90%), which means that 90% of the data that the CPU will read next time are in the cache, only about 10% Need to read from memory. This greatly saves the time for the CPU to directly read the memory, and also makes the CPU basically no need to wait when reading data. In general, the order in which the CPU reads data is cached first and then memory. The earliest CPU cache is a whole, and the capacity is very low, Intel has classified the cache since the Pentium era. At that time, the cache integrated in the CPU core was not enough to meet the needs of the CPU, and the limitations on the manufacturing process could not greatly increase the capacity of the cache. Therefore, there is a cache integrated on the same circuit board or motherboard as the CPU. At this time, the cache integrated with the CPU core is called the first level cache, and the external one is called the second level cache. The first level cache is also divided into data cache (Data Cache, D-Cache) and instruction cache (InstrucTIon Cache, I-Cache). The two are respectively used to store data and execute instructions for these data, and both can be accessed by the CPU at the same time, reducing conflicts caused by contention for Cache, and improving processor performance.

How to turn off the second level cache

Solution:

After turning on the power, when the CPU frequency and memory capacity appear, press the DEL key to enter the CMOS SETUP page.

Enter BIOS→Advanced BIOS Features

→CPU L1 & L2 Cache (CPU primary and secondary cache)

Turn on (Enabled) or turn off (Disabled) CPU internal cache (L1) and external cache (L2);

(Press Page UP/Down key to switch).

Press Esc to return to the COMOS SETUP page, move the cursor to SAVE&EXIT SETUP, type Y and press Enter

How to clean up the secondary cache

* The save, update, saveOrupdate, load, get, list, query, and Criteria methods will all fill the secondary cache

* get, load, iterate will fetch data from the secondary cache

* session.save (user) If the user primary key is generated using "naTIve", it will not be placed in the secondary cache.

(1) Turn on the secondary cache

"Property name="cache.use_second_level_cache""true "/property"

(2) Specify the implementation class of the second-level cache for hibernate

"Property name="cache.provider_class""

org.hibernate.cache.OSCacheProvider

"/Property"

(3) Create a configuration file for OSCache cache (requires hibernate_Advance_Surpport_lib)

src/oscache.properTIes

Modify the configuration:

cache.capacity=1000 specifies how many objects the cache can hold

(4) Specify which classes need to be placed in the second-level cache, and objects that need to be used for a long time need to be placed in the second-level cache

"Class-cache class="enTIty.PetInfo" usage="read-only" /" //It is not allowed to update the objects in the cache

"Class-cache class="entity.PetInfo" usage="read-write" /" //Allows to update the objects in the cache

Or in the orm file:

"Class name="entity.PetInfo" table="PetInfo" schema="dbo" catalog="epet""

"Cache usage="read-only"/"

. ..

"/Class"

(5) If you need to clear the secondary cache, use the following syntax

sessionFactory.evict (User.class) clear all users

sessionFactory.evict (User.class, Id) clear the specified user

How to use secondary cache

*1. Introduce the following jar packages.

ehcache-1.2.3.jar core library

backport-util-concurrent.jar

commons-logging.jar

*2. Configure Hibernate.cfg.xml to enable secondary cache

"Property name="hibernate.cache.use_second_level_cache"" true "/property"

*3. The vendor who configures the secondary cache

"Property name="hibernate.cache.provider_class"" org.hibernate.cache.EhCacheProvider "/property"

Configure in the big configuration file (hibernate.cfg.xml)

"Class-cache usage="read-write" class="cn.happy.entity.Student"/"

"Collection-cache usage="read-write" collection=""/"

The principle of storing data in the secondary cache:

How to clean up or close the second-level cache

Conclusion

This is the end of the related introduction about the second-level cache. If there are any deficiencies, please correct me.

Mono Solar Panel

zhejiang ttn electric co.,ltd , https://www.ttnpower.com

Posted on