External Memory : In addition to computer memory and CPU cache memory, such as Common C, D, E, f disk, there are U disk, floppy disk, hard disk, CD-ROM and so on. The integrity of the data can still be saved after a power outage.
memory : Used to communicate with the CPU. All programs in the computer are carried out in memory, and all the operational data in the CPU and the data exchanged between and external memory are stored. Data loss is not saved.
High-speed buffering : In general, the CPU processing data is very fast, and the memory speed is relatively slow, easy to cause performance problems, to solve this problem using high-speed buffering. Principle: The system in the high-speed buffer area to store the CPU frequently accessed data, when the CPU access to a data, first in the buffer to find, not found in the memory to find, greatly improving the efficiency of the CPU operation.
When some resources or data are used frequently, and these resources or data are stored outside the system, such as databases, hard disk files and so on, each time the data is taken from the database or hard disk to obtain, the speed will be slow, will cause performance problems.
Most of the time we do development in the unconscious with the cache, common multi-threaded memory visible, character stream and IOC are cached
1. Map
Based on the memory cache, a map can take care of the cache of reference objects, the problem is that the validity of the preservation object and the life cycle can not be controlled, improper handling will lead to a sharp rise in memory, not suitable for large data volume of the cache.
Need to define a cache manager, for the implementation of caching logic, the implementation of object additions and deletions, support the generic type of the value object, is actually put the data in the map
Import above the service layer Cachecontext
2. Springcache annotation @cacheable (value = "Accountcache")
This annotation means that when this method is called, it is queried from a cache called Accountcache, and if not, the actual method (that is, querying the database) is executed, and the result of execution is cached, otherwise the object in the cache is returned. The key in the cache here is the parameter accountname,value is the account object. The "Accountcache" cache is the name defined in the Spring*.xml. We also need a spring configuration file to support comment-based caching
Add AccountService2 based on the above
Need to configure Cachmenager,bean inside the spring Accountcache
Note This spring configuration file has a key cache-enabled configuration entry:
<cache:annotation-driven/>
Java Cache (bottom)