Some questions about the cache

First, what is the cache
1, Cache memory is a special cache memory subsystem in which frequently used data copied to facilitate quick access to
2, all of the velocity difference between the larger two hardware / software, with to coordinate the transmission speed of both the difference data structures, it can be referred to as Cache

Second, the classification of the cache
1, is based on web applications

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

  • The operating system disk cache -> disk to reduce mechanical operation
  • Database Cache -> reduce the file system I / O
  • Application Cache -> reduce database queries 
  • Web server cache -> reduce application server requests
  • The client browser cache -> reduce access to websites

Third, the operating system cache
1, Disk Cache file system provides: The operating system will often have access to the contents of the file into memory which, by the file system to manage
2, when an application when accessing disk files through the file system, operating Disk Cache system reads from among the contents of the file, the file read speed acceleration
3, Disk Cache automatically managed by the operating system, usually without human intervention, but should ensure adequate physical memory, so that the operating system can use as much memory to act as disk Cache, speed up file read speed
4, a special application for file system disk Cache has a high demand, bypasses the file system disk Cache, direct access to the disk partitions to achieve their own disk 
5, Cache policy

  • Oracle's raw device (raw device) - Direct abandon File System
  • MySQL的InnoDB: innodb_flush_method = O_DIRECT


Fourth, the database cache
1, the importance of

  • Database is usually the core part of enterprise applications
  • The amount of data stored in the database are usually very large
  • Database queries are usually very frequent, and sometimes very complex
  • Database query above reasons can cause very frequent disk I / O read operation, forcing the CPU suspends waiting, database performance is extremely low

2, cache strategy
     a, Query Cache

    • As a key value to the SQL query result set caching
    • Once a query involving a table record is modified, the cache will be automatically deleted
    • Set the appropriate Query Cache will greatly improve database performance
    • Query Cache is not always better, too large Qquery Cache memory is wasted.
    • MySQL: query_cache_size= 128M

     b、Data Buffer

    • a data buffer container database data in memory
    • Data buffer hit ratio directly determines the performance of the database
    • data buffer bigger the better, the more the better
    • MySQL的InnoDB buffer:innodb_buffer_pool_size = 2G
    • MySQL recommended buffer pool open large physical memory to the server 60-80%

Fifth, the application cache
1, object caching

  • Hibernate is provided by, for example, O / R Mapping framework, access transparency, fine-grained cached database query results, without explicit programming service code, caching policy is the most convenient
  • When the specific design software structure, will greatly reduce the use of object caching Web access to the system as required database request O / R Mapping framework
  • A well-designed database structure and use of object caching, can provide high performance, object cache for OLTP (online transaction processing) applications

2, query cache

  • Database query result set caching, similar Query Cache database
  • It applies to some time-consuming, but the timeliness requirements are relatively low scenarios. Query caching and object caching applicable scene is not the same, are complementary
  • When the query result set table records involved are modified, you need to pay attention to clear the cache

3, page caching
     a, role

    • For page caching technology can not only reduce the pressure of the database server, application server can also relieve pressure
    • Good page caching can dramatically improve the speed of page rendering
    • Page cache difficulty is how to clean up expired cache

    b, Category
         I, dynamic static pages

    • Using the template technology will be accessed dynamically generate static html page once, and modify the page link, the next request direct access to static link page
    • Dynamic page static technology is widely used in Internet CMS / news Web applications, but there are also BBS application of this technique, for example Discuz!
    • Permissions can not be verified, personalized information can not be displayed
    • Some disadvantages of using AJAX request to make up a dynamic static pages

        II, Servlet cache

    • URL for the page cache access results returned for coarse-grained page cache, such as press releases
    • You can check permissions
    • OScache provides a simple Servlet cache (by web.xml configuration)
    • You can own programming Servlet caching

        III, page internal cache

    • For partial fragment caching dynamic pages of content for personalized pages of some, but not frequently updated (eg blog)
    • OSCache provides a simple page cache
    • You can expand their own JSP Tag achieve the page cache


Six, web server-side caching

  • Based on the Web server side caching proxy mode, such as squid / nginx
  • Web server caching technology used to implement CDN (content delivery network content delivery network)
  • The extensive use of domestic mainstream portals
  • No programming is required, but only press release website, less demanding real-time page

Seven, ajax-based browser cache

      • Use AJAX call when the database in the browser cache
      • You do not leave the current page, without refreshing the current page, you can read cache data directly
      • It applies only to the page using AJAX technology

Guess you like

Origin www.cnblogs.com/pxzbky/p/11415794.html