Atitit Cache Attilax Etti Summary 1. Use cache for purposes (using cache) 1 1.1. 1, to achieve the goal of reducing the burden of the database 1 1.2. Speed up queries by 2 2. The common parameters of the cache are too

Source: Internet
Author: User
Tags redis serialization browser cache

Atitit Cache Caching Path Attilax Etti Summary

1. Purpose of using caching (using cache) 1

1.1.1. Reduce the burden on the database by achieving the target 1

1.2. Speed up the query 2

2. Common parameter expiration time of the cache (seconds 2

3. Cache implementation away from principle 2

4. Cache Standard Jcache 2

5. Caching the implementation of common APIs 2

5.1. Get Cache 2

6. Cache refresh Time Mechanism 3

7. Cache hierarchy in the system architecture, in order to speed up access between different levels, the cache can exist 3

7.1. Indexdb Localstore 3

7.2. Redis 3

7.3. ORM Cache 3

7.4. Dbcache 3

8. Four, Database Cache 4

8.1.2, Cache policy A, Query cache 4

8.2. B, Data Buffer 4

9. Cache algorithm FIFO,LRU and LFU three types 4

10. Common Cache implementations 5

10.1. Prioritize the use of spring cache Mybatiscacahe to minimize development 5

10.2. Guavacache Ehcache workload is slightly larger, single reliability is high. 5

10.3. Thread pool Futuretask write cache requires adjustment order 5

10.4. Redis most Troublesome Write 5

11. Other 7

11.1. Key generation algorithm that getmethodname+ param serialization 7

1. use cache for purposes (using cache) 1.1. 1, to achieve the goal of reducing the burden of the database

data is cached through Redis. (The goal is not to speed up the query, but to reduce the burden on the database) 1.2. speed up your queries 2. cache Common parameter expiration time (in seconds

1. private int maxsize=default_maxsize; Maximum number of digits

2. private int Ttl=default_ttl; Expiration Time (seconds)

3. caching implementation away from the principle

The most cached solution is to store the data in a map-like structure (Key-value), which is why the standard of the Jcache API specification is also based on a map (similar) structure.

Local tables can also be

List cache, conditional query Wehere cache

In fact, the cache is to save some external memory data to memory, how to save to memory, we run all programs, the value of the variables are placed in memory, so if you want to put a value in memory, the essence is to get this variable, with a long-lived variable to store the value you want to store, In Java, some caches are generally done through the map collection.

4. Cache Standard Jcache 5. caching the implementation of common APIs 5.1. get cache

Get, you can set a call if it does not exist.

Using the ex mode is not good, and using the return value is not good either.

6. cache refresh time mechanism

If the cache is supported, you can set it directly.

if the cache does not support you can use the timer to refresh actively: 7. Cache Hierarchy in the system architecture, in order to speed up access between different levels, the cache can exist

· 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

7.1. indexdb localstore

Operating system disk Cache--Reduced disk mechanical operations Database Cache--Reduced file system I/O application Cache--Reduce query to database Web server cache--Reduce application server requests client browser cache--reduce access to web sites

7.2. Redis 7.3. ORM Cache 7.4. dbcache

8. Database Cache

1. Importance

The database is usually the core of the enterprise Application System. The amount of data stored in a database is usually very large database query operations are often very frequent, and sometimes complex cause database queries cause very frequent disk I/O read operations, forcing the CPU to suspend waiting, database performance is extremely low   8.1. 2. Cache policy A, Query cache

Cache query result set with SQL as key value once the query involves a record of the table being modified, the cache will be automatically deleted setting the appropriate query cache will greatly improve the database performance query cache is not as large as possible, the Qquery cache will waste memory MySQL : query_cache_size= 128M 8.2. B, Data Buffer

Data buffer is the database data in memory container the hit ratio directly determines the performance of the database the larger the better, the better, the more mysql innodb buffer:innodb_buffer_pool_size = 2GMySQL buffer pool is recommended to open to server physical memory 60-80%

9. cache algorithm FIFO,LRU and LFU three kinds

Mainly divided into Fifo,lru and lfu three species, in the technical point will explain the meaning of these three. We study and optimize together. The author of the current arrangement of some blog for the interview is UHF appeared. You can click on the link: http://blog.csdn.net/u012403290

Technical points:

1, FIFO (first in first out):
First-in, first-out, well understood, as in the queue, advanced queue of first-out queue.

2, LRU (Least recently used):
Least recently used, meaning that the most recently read data is placed in the front, the earliest reading of the data is placed on the last side, if there is new data coming in, then the most back-stored data obsolete.

3, LFU (Least frequently used):
Most infrequently used, meaning that there is a count reference to the stored data, and then the queue is sorted by the number of data references, the number of references is the first, and the number of references is less than the row. If there is new data coming in, delete the last data, put the new data in the last, and the number of references is 1.

10.1. Common cache implementations . prioritize the use of spring cache Mybatiscacahe minimized development 10.2. Guavacache Ehcache workload is slightly larger, single reliability is high.  10.3 . thread pool Futuretask write cache needs adjustment order 10.4. Redis Most troublesome to write

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 business code explicit programming, is the most hassle-free caching strategy when the software structure is designed according to the requirements of the O/R mapping Framework, Using object caching will greatly reduce the Web system's access to the database to a well-designed database structure and the use of object caching, which provides very high performance and object caching for OLTP (online transaction processing) applications

2. Query cache

Caching database query result sets, database-like query caches are useful for scenarios that are time-consuming, but have low timeliness requirements. The query cache and the object cache are not the same scenarios and 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 technology for the page not only can reduce the pressure of the database server, but also reduce the application Server pressure good page cache can greatly improve the page rendering speed the difficulty of page caching is how to clean up outdated caches

B, classification

I, dynamic page static

Using template technology to generate static HTML for dynamic pages visited once, while modifying page links, next request direct access static link page 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, cannot display personalization information some drawbacks of dynamic page statics can be compensated using AJAX requests

II, servlet cache

Cached for page results returned by URL access, for coarse-grained page caches, such as press releases for permission checks Oscache provides a simple servlet cache (through configuration in Web. xml) and can be programmed to implement the servlet cache yourself

III, page internal cache

Caching of local fragment content for dynamic pages, for some personalized but infrequently updated pages (such as blogs) Oscache provides a simple page cache that can extend the JSP tag to implement the page local cache

Vi. Web server-Side Caching

Proxy server-based Web server-side caching, such as the Squid/nginxweb server cache technology, is used to implement CDN (content distribution network contents delivery Networks) is widely used in domestic mainstream portals do not need programming, but limited to the news publishing site , the page real-time requirements are not high

VII. Ajax-based browser caching

When using AJAX calls, the database is cached on the browser side as long as you do not leave the current page, do not refresh the current page, you can directly read the cache data only for the use of AJAX technology pages

One . others 11.1. key generation algorithm that getmethodname+ param serialization

Write the annotation @Cacheable at the service layer (value = "Mycache", key = "getmethodname ()")

Serialization of getmethodname+ param

Dry _java caching technology. HTML

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.