Home > Java > javaTutorial > body text

Introduction to java caching technology

黄舟
Release: 2017-02-06 16:14:43
Original
1260 people have browsed it

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

Introduction to java caching technology

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

## b. Data Buffer

  • data buffer is database data Containers in memory

  • The hit rate of the data buffer directly determines the performance of the database

  • The bigger the data buffer, the better, the more the better

  • MySQL's InnoDB buffer: innodb_buffer_pool_size = 2G

  • MySQL recommends that the buffer pool be opened to 60-80% of the server's physical memory

5. Application cache

1. Object cache

  • Provided by O/R Mapping framework such as Hibernate, transparent access, fine-grained caching of database query results , without explicit programming of business code, is the most trouble-free caching strategy

  • When the software structure is specifically designed according to the requirements of the O/R Mapping framework, using object caching will greatly reduce Web system's access request to the database

  • Good design of database structure and use of object cache can provide extremely high performance. Object cache is suitable for OLTP (online transaction processing) applications

2. Query Cache

  • Cache the database query result set, similar to the database Query Cache

  • is applicable It is suitable for some scenarios that are time-consuming but have low timeliness requirements. Query caching and object caching are applicable to different scenarios and are complementary to each other

  • When the table records involved in the query result set are modified, you need to pay attention to clearing the cache

3. Page caching

a. Function

  • Cache technology for pages can not only reduce the pressure on the database server, but also reduce the pressure on the application server

  • Good page caching can greatly improve page rendering speed

  • The difficulty of page caching is how to clean up expired cache

b. Category

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

  • ##Web server caching technology is used to implement CDN (content distribution network content delivery network)

  • is widely used by domestic mainstream portal websites

  • No programming is required, but it is limited to news release websites, and the page real-time requirements Not high

7. Ajax-based browser caching

  • When using AJAX to call, cache the database on the browser side

  • As long as you do not leave the current page or refresh the current page, you can directly read the cached data

  • Only applicable to pages using AJAX technology



The above is the introduction of java caching technology. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!