Java Caching Technology

Source: Internet
Author: User

Excerpt from: http://symphony.b3log.org/article/1376986299174

First, what is the cache
1, Cache is a special memory subsystem of buffer memory, which replicates frequently used data to facilitate fast access
2, generally located in the speed difference between the two hardware/software, to coordinate the data transmission speed differences between the structure, can be called the Cache

Second, the classification of the cache
1. System architecture diagram based on Web application

2, between different levels of the system architecture, in order to speed up access, there can be a cache

    • Operating system disk cache, reducing disk mechanical operation
    • Database cache, reducing file system I/O
    • application caching, reducing queries to the database
    • Web server cache, reducing application server requests
    • Reduce access to Web sites with client browser caching

Third, the operating system cache
1, the file system provides disk Cache: The operating system will frequently access to the contents of the file into memory, by the file system to manage
2, when the application through the file system access to disk files, the operating system from disk cache read the contents of the file, speed up the file read speed
3, Disk cache by the operating system to automatically manage, generally without manual intervention, but should ensure sufficient physical memory to facilitate the operation of the system can use as much memory as Disk Cache, speed up the file read speed
4, the special application of the file system disk cache has a high demand, will bypass the file system disk cache, direct access to disk partitions, their own implementation disk
5. Cache Policy

    • Oracle's raw device (bare devices) – discards the file system directly
    • MySQL's Innodb:innodb_flush_method = O_direct


Iv. Database Caching
1. Importance

    • A database is usually the most central part of an enterprise application system.
    • The amount of data stored in a database is usually very large
    • Database query operations are often frequent and sometimes complex
    • This causes database queries to cause very frequent disk I/O read operations, forcing the CPU to suspend waiting and database performance to be extremely low

2. Cache Policy
A, Query Cache

      • Cache query result set with SQL as key value
      • Once the table records involved in the query are modified, the cache is automatically deleted
      • Setting the appropriate query cache can greatly improve database performance
      • Query cache is not as big as possible, and the qquery cache is too large to waste memory.
      • Mysql:query_cache_size= 128M

B, Data Buffer

      • Data buffer is the container in memory of the database
      • Data buffer's hit rate directly determines the performance of the database
      • The larger the data buffer, the better.
      • MySQL InnoDB buffer:innodb_buffer_pool_size = 2G
      • MySQL recommends buffer pool open to server physical memory 60-80%

V. Application caching
1. Object Cache

    • Provided by the O/R mapping framework such as hibernate, transparent access, fine-grained cache database query results without explicit programming of business code, is the most convenient caching strategy
    • When the software architecture is designed according to the requirements of the O/R mapping framework, using object caching will greatly reduce the Web system's request for access to the database
    • Good design of database structure and the use of object caching to provide very high performance, object caching for OLTP (online transaction processing) applications

2. Query cache

    • Cache database query result set, database-like query cache
    • Suitable for some time-consuming but low-timeliness scenarios. The query cache and the object cache are not the same scenarios, they are complementary to each other
    • When the table records involved in the query result set are modified, you need to be careful about cleaning up the cache

3. Page Cache
A, the role

      • Caching for pages not only relieves database server pressure, but also eases application server stress
      • Good page caching can greatly improve page rendering speed
      • The difficulty with page caching is how to clean up outdated caches

B, classification
I, dynamic page static

      • Use template technology to generate static HTML for dynamic pages visited once, while modifying page links, next request direct access to static link pages
      • Dynamic page static technology is widely used in Internet cms/news Web applications, but there are BBS applications that use this technology, such as discuz!
      • Cannot perform permission validation and cannot display personalization information
      • You can use AJAX requests to compensate for some of the drawbacks of dynamic page statics

II, servlet cache

      • Cached for page results returned by URL access, for coarse-grained page caches, such as press releases
      • You can check for permissions
      • Oscache provides a simple servlet cache (via config in Web. xml)
      • You can also programmatically implement the servlet cache

III, page internal cache

      • Caching local fragment content for dynamic pages for pages that are personalized but infrequently updated (such as blogs)
      • Oscache provides a simple page cache
      • Self-expandable JSP tag for page local cache


Vi. 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 delivery)
    • By the domestic mainstream portal site a large number of adoption
    • Do not need programming, but limited to the press release of the site, the page real-time requirements are not high

VII. Ajax-based browser caching

    • When using AJAX calls, cache the database on the browser side
    • You can read the cached data directly without leaving the current page without refreshing the current page.
    • Applies only to pages that use AJAX technology

Java Caching Technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.