Home >Java >javaTutorial >Introduction to java caching technology
1. What is cache
1. Cache is a special memory subsystem of cache memory, in which frequently used data is copied to facilitate quick access
2. Any data located between two locations with a large speed difference A structure between hardware/software used to coordinate the difference in data transmission speed between the two can be called Cache
2. Classification of cache
1. System architecture diagram based on web applications
2. In order to speed up access, there can be cache between different levels of the system architecture.
Operating system disk cache ->Reduce disk mechanical operations
Database cache->Reduce file system I/O
Application cache->Reduce requests for Database query
Web server cache->Reduce application server requests
Client browser cache->Reduce visits to the website
3. Operating system cache
1. Disk Cache provided by the file system: The operating system will put the contents of frequently accessed files into the memory and be managed by the file system
2. When an application accesses a disk file through the file system, the operating system reads the file content from the Disk Cache, speeding up the file reading speed.
3. The Disk Cache is automatically managed by the operating system and is generally not used. Manual intervention, but sufficient physical memory should be ensured so that the operating system can use as much memory as possible to serve as Disk Cache and accelerate file reading speed
4. Special applications have high requirements for the file system Disk Cache, which will Bypass the file system Disk Cache, directly access the disk partition, and implement Disk yourself
5, Cache strategy
Oracle’s raw device (bare device) – directly abandon the file system
InnoDB of MySQL: innodb_flush_method = O_DIRECT
4. Database cache
1. Importance
The database is usually the core part of the enterprise application system
The amount of data stored in the database is usually very large
Database query operations are usually very frequent. Sometimes it is very complicated
The above reasons cause database queries to cause very frequent disk I/O read operations, forcing the CPU to hang and wait, and the database performance is extremely low
2. Cache strategy
a. Query Cache
Use SQL as the key value to cache the query result set
Once the table records involved in the query are modified, the cache will be automatically deleted
Setting the appropriate Query Cache will greatly improve database performance
The bigger the Query Cache, the better. An overly large Qquery Cache will waste memory.
MySQL: query_cache_size= 128M
1. Object cache
a. Function
I. Dynamic page staticization
Use template technology to generate static html from the dynamic page visited once, and modify the page link at the same time. The next request will directly access the static link page
Dynamic page Static technology is widely used in Internet CMS/news Web applications, but there are also BBS applications that use this technology, such as Discuz!
Cannot perform permission verification and cannot display personalized information
You can use AJAX requests to make up for some shortcomings of static dynamic pages
II, Servlet caching
Cache the page results returned by URL access, suitable for coarse-grained page caching, such as news releases
Permissions can be checked
OScache provides a simple Servlet cache (through configuration in web.xml)
You can also program your own Servlet cache
III. Page internal caching
Cache local fragment content of dynamic pages, suitable for some personalized but infrequently updated pages (such as blogs)
OSCache provides simple page caching
You can extend JSP Tag by yourself to implement partial caching of the page
6. Web server-side caching
Web server-side caching based on proxy server mode, such as squid/nginx