Full-stack Prerequisite cache Caches

Source: Internet
Author: User
Tags jboss smarty template varnish redis cluster

CACHE:A Collection of data duplicating original values stored elsewhere on a computer, usually for easier access--wikipedia

Caching is a key technology in a system's rapid response, a set of things that are saved for future use, between application development and system development, where product managers are often not aware of the non-functional constraints of the technical architecture.

In other words, caching is a frequently used and effective means of system tuning, and the caching strategy is ubiquitous in both the operating system and the application system.

Many technologies are under the banner of caching, so talking about caching is often specious, and context has a close relationship, in other words, look at the cache in different scenarios of classification.

Client-Side Caching

The browser's cache can save the previously rendered page as a file, allowing users to bypass the network connection when they visit again, thereby reducing the load. The HTML5 now supports local storage, and most BS applications can be juchongruoqing.

How to update the client cache for business component transparency and client cache data is the key to the successful application of client cache.

Clients can cache content in memory, in a file, or in a local database (such as SQLite).

For example, the picture cache framework for IOS Sdweb the following schema:

Web Proxy

The role of Web Proxy is similar to the browser's built-in cache, just between the browser and the Internet, where network requests are relayed through proxies. For the enterprise, it can save cost, but also can improve performance.

For web proxies, squid was once popular, supporting the ability to build complex cache hierarchies, verbose logging, high-performance caching, and user authentication support. Squid supports a variety of plugins, such as Squid guard, a plug-in that provides URL filtering, and is useful for blocking certain sites and content. If you want to analyze squid's various indicators, Webalizer should be a good choice.

The internal mechanism of SQUID is as follows:

Edge Caching

The edge cache is located in front of the application server and can handle requests from different users, primarily to provide static content to the user to reduce the intervention of the application server. The commercial service of Edge caching is CDN, such as AWS Cloud Front, our country's chinacache and so on.

A well-known open source tool for edge caching is varnish, which is conservatively cached by default. In other words, varnish only caches the security content it knows. One feature of varnish is the use of virtual memory, the subtlety of which is the use of operating system management mechanisms. Varnish can highly customize how requests are processed and what is cached.

The internal mechanisms of Varnish are as follows:


See www.varnish-cache.org for details.

Platform Cache

The platform cache is a framework for writing applications, or a dedicated library for caching (such as the Smarty Template Library in PHP).

In the Java language, caching frameworks are more, such as Ehcache,cacheonix,voldemort,jboss cache, and so on.

Take a look at the system structure of the Ehcache:

Ehcache is a Java-implemented open-source distributed cache framework that allows data to be stored in memory on different servers and can be accessed quickly when data is needed. Different parameters are passed in by declaring the configuration, configuring in XML, configuring in a program, or invoking a constructor method.

Voldemort is a Java-based distributed key-value caching system, like JBoss Cache, Voldemort also supports cache synchronization between multiple servers to enhance system reliability and read performance.

Simply put, in the case of platform-level caching, you only need to configure the properties on the frame side, rather than calling a specific method or function.

App Cache

Application-level caching requires you to implement the cache yourself through code. This is the NoSQL wins, whether Redis or MongoDB, which can be used as a tool for caching applications. A typical approach is to generate a class of pages that are stored in the cache every minute or a period of time, or to update the cache when hot data changes.

The role of Redis in the application-level cache is significant, with Sina Weibo having the world's largest redis cluster. Redis supports master-slave synchronization. Data can be synchronized from the primary server to any number of slave servers, from the server to the primary server that is associated with other slave servers. This enables Redis to perform single-layer tree replication. You can write to the data intentionally or unintentionally. Because of the full implementation of the publish/subscribe mechanism, you can subscribe to a channel and receive a complete message release record from the master server when the tree is synchronized anywhere from the database. Synchronization is helpful for the scalability and data redundancy of read operations.

Redis has a wide range of client programming languages to satisfy most applications.

Database Cache

The database cache is a special kind of cache. Most databases do not need to be configured to run quickly, but are not optimized for specific requirements. Cache optimization is a very important task when tuning a database.

In MySQL, for example, the query buffer mechanism is used in MySQL, the SELECT statement and query results are stored in the buffer, and later for the same SELECT statement, the results will be read directly from the buffer to save the query time and improve the efficiency of SQL query.

By adjusting the following parameters you can know whether the query_cache_size is set properly:

    • Qcache Inserts
    • Qcache Hits
    • Qcache Lowmem prunes
    • Qcache Free Blocks
    • Qcache Total Blocks

Of course, there is a lot to learn about the database in depth.

Cached protocol Support

For Web applications, http1.0 provides some very basic caching features, such as setting the expires HTTP header on the server side to tell the client how long the cache is safe before requesting the file, and can use the cache through If-modified-since conditional requests. Where the time to send is the time when the file was initially downloaded, not the time it will expire, and if the file does not change, the server can respond with 304-not Modified. When the client receives 304 code, it can use the cached file version. The client can set Pragma:no-cache to get content from the server.

Http 1.1 has a large enhancement, the caching system has been formalized, introduced the entity tag E-tags, is a file or object unique identification. This means that you can request a resource, provide the file you hold, and then ask the server if the file has changed. If the e-tag of a file is valid, the server generates a 304-not Modified answer and provides e-tag of the correct file, otherwise, sends a 200-OK reply. The browser example is as follows:

There is still a need to study the caching techniques in HTTP2.0.

All in all, the cache--cache, is a very complex technology, in addition to the application scenario, but also to understand the hit, cache Miss, storage cost, index cost, invalidation, alternative strategies of many concepts, so as to understand the cache algorithm, the real master caching technology.

Full-stack Prerequisite cache Caches

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.