What is cache? For beginners, it may be vague, or they only know that it is a matter of improving performance. In my understanding, the purpose of caching is to improve performance and store some data in the memory for convenience. Program The cache is the data stored in the memory. When developing a program, for example, defining a static variable, the value of this static variable is generally stored in the memory, and this variable is cached. Of course, this cache is called for the first time until the end of the program. It does not mean that only global static variables are called cache. For example, if we declare the current context (currentcontext) at the beginning of an httprequest request, we can obtain the current context throughout the lifecycle of the page, and the context is also cached. If we put the complex data query results in a data table for other programs to call, then this temporary table is a cache table and a cache. In short, cache exists to improve performance. Cache is to open up some internal space in exchange for the running time of the program.
In our daily work of development, we often encounter various caches. The most common is browser cache, which often requires a strong refresh to see the page modification results. This is the browser's cache policy. You refresh some pages multiple times. If you use firebug, ie9's web development tool (F12), or Chrome's built-in development tool (CTRL + Shift + C) or httpwatch, you can observe the network item to see the status of all HTTP requests. If it is cached, the status is not 200, but 304 (not modified ), in this way, your server will not receive this request. Generally, static resources (images, JS, CSS, and HTML) are cached.
There is also dataset (classes in ADO. Net, which may not be clear to non-. Net programmers ). Dataset is one of the highlights of ADO. net compared with ADO. When it is highlighted, it does not need to be connected to the database all the time. He first reads the data into the able, and then the programmer processes the data for the datatable. The purpose of this operation is not to occupy the database connection. If each data processing item of the user is time-consuming and datareader is used instead of dataset, if the traffic volume is a little large, an exception with too many connections or too many connections will occur, leading to a timeout exception or a very tight database, resulting in all queries being slow. Therefore, this dataset is also the concept of caching. Although it may be just a short method life cycle, its idea remains unchanged.
After understanding the meaning of the cache, how can I use the cache? Let's first think about what data can be cached or needs to be cached? Generally, data is commonly used, and public data needs to be cached. It is usually compared with programs, such as website configuration information that needs to be called everywhere. It is best to cache it. In public, the private information of a viewer is not suitable for caching, such as account information, which is generally stored by session. In fact, the session is also cached. The session value is stored in the memory of the server, and each session corresponds to a sessionid. The sessionid information is stored in the cookie of the client. Each time the program calls the session value, it first needs to find a sessionid from the cookie sent by the browser, and then find the session value corresponding to the ID from the memory, so the session is also cached. However, I am saying that public data is not suitable for storing private data of users in the cache we will talk about in the future.
From the perspective of cnblog, compared with the public information of the viewer, there are blog materials, sidebar,ArticleComments, in addition to the viewer's own information, it seems to be public information. Do they all need to be cached? That is, it depends on the necessity of caching. If notCnblogBut a personal blog with a low access volume. If public data is cached, it will inevitably feel a bit difficult. Because the traffic is not large, it is cache. This performance improvement is meaningless. In terms of development, A large amount of work is added (Cache updates are involved for every addition, modification, and deletion ).CnblogIf the database is not cached, the database may be unable to cope with the issue for a long time. It can be seen that cache is also a double-edged sword, and the quality of use depends on the needs of the project.
Today, let's start with an introduction. I will analyze the blog's Cache architecture and use various cache technologies and strategies. Do not miss out.