Andrews how to master the advanced development interview knowledge? Cache focus in this!

Foreword

Before long we said that we want to organize a collection of easy, but fortunately did not drag 2020
BATJ, byte beating interview topics, topics algorithms, high-end technology topics, mixed-use development themes, java interview topics, Android, Java little knowledge, to performance optimization thread .View.OpenCV.NDK, I have already uploaded to my GitHub

Click on my GitHub address:https://github.com/Meng997998/AndroidJX learn together under the star point

Well, follow me today, to tell you the focus of the cache, along with skilled master Andrews advanced development interview knowledge!

We all know that almost all the projects have done a cache, but the cache of how to do, in fact, only everyone they know.
Cache do good, no network can smooth use; no amount of data requests are cases Caton delay waiting for a long time does not appear.

Program in addition to the image cache (level three cache), and the cached information. When a user can not networking, app cache data will be displayed by default.

### Foreword cache mode

SQLite

After downloading the data file, the file-related information such as url, path, download time, the expiration time stored in the database, the url as a unique identifier. The next time you download url start time based on the database query, if the query to the current time has not expired, according to a local file path is read, enabling caching effects.

File cache File.lastModified () method to get the last modified time of the file, and determines whether the current time is expired, thereby achieving the effect of the cache. Data format JSON.

Cache mode just two points

1, a cache file of a different type of time is not the same. General said, the same time the cache file is permanent, the cache file is the greatest time to endure the same time. He said the white point, the contents of the image file is unchanged, there is generally on the SD card until clean-up, we can read cache forever. It is possible to update the configuration files, you need to set an acceptable buffer time.

2, the standard buffer time is not the same in different environments. No network environment, we can only read cache files, use something to show, nothing is said of the expired.

WiFi

Under the network environment, the cache can be set shorter time, first speed is faster, but not the money flow.

3G

Under traffic environment, the cache time can be set a little longer, save traffic, but also a better user experience.

Cache Time

Cache Time app in multiple pages is not the same, real-time requirements of high page cache shorter. The http header contains cache time, android end without their recording / predetermined buffer time can be read.

http protocol support for caching

Expires & Cache-Control

Expires response header gives the absolute failure of response time, so that the client can cache a copy before the time expires,

You do not have to ask the server if it is valid. http1.0 introduced. Example: Expires: Thu, 03 Oct 1997 17:15:00 GMT

Cache-Control headers for caching information transfer objects. http1.1 introduced. Its value is an instruction cache, an object may be given with specific instructions related to cacheability. This header may occur in the request or response header. For example: Cache-Control: no-cache

CacheControl

There are two fields in response to the expiration time of the expression: max-age, and max-stale

The former says: max-age within seconds, and then the page is requested, well you do not come to my server, takes you directly to the results of the local cache

The latter said: requests within seconds max-stale, you can use a local cache, but I still want to ask the server, all right in the end, of course, here to bring Last Modified information, if the server returns a 304 , that you continue to use the local cache, and I do not give you 200 words in response, the body naturally bring a response.

Cache-Control and Expires action consistent refer period current resource control is to obtain data directly from the cache or fetch requests to the server to resend the data.

Caching algorithms

1, the LRU  - least recently used (last access time) to replace the document recently requested the least. The traditional strategy in practice most widely used. Eliminated in the CPU cache and virtual memory system is better.

2, the LRU-the K

LRU-K

K represents the number of recently used, can also be considered LRU-1. The main purpose of LRU-K is to solve the problem "cache pollution" LRU algorithm, the core idea is to extend the "recently used one time," the criteria for the "recently used K times." Compared LRU, LRU-K need more to maintain a queue for history being accessed recorded all cached data. Only when the number of accesses data reaches K times before the data into the cache. When the need to eliminate the data, LRU-K would eliminate K-th access time from the current time the largest data. as follows:

Andrews how to master the advanced development interview knowledge?  Cache focus in this!

  1. LFU  - Least often replace the use of minimum number of visits (visits). This strategy intent to retain the most commonly used and most popular object, replace those rarely used.

LFU

Each data block has a reference count, the reference count of all blocks of data sorted in accordance with the reference count of the same data block is sorted by time. as follows:

Andrews how to master the advanced development interview knowledge?  Cache focus in this!

  1. SIZE (cache size) to replace the largest target size. This strategy to improve the hit rate through the elimination of a large object, instead of multiple small objects. However, there may be some small objects into the cache will never be accessed again. SIZE policy does not provide a mechanism to eliminate this type of object, would lead to "cache pollution" (a large number of occasional access to data stored in memory so that a large number of cold data, that is, cache pollution).

Extended a few questions, frequently asked interview questions:

1, http caching is how to do?
2, what is the use? (This issue together with thread and ask, ask a general.)

Answer your own Baidu. Then I do not talk about it. Because I read http source, read his cache and threads. It is customizable. Do an understanding on the line.

The question asked is not high frequency. The high-frequency generally ask this question: Is there a web request, there is a lot of data (such as one, two, daily data must request it), and then get the deal done after the data, then recycleview (or listview) displayed. Like many such requests due to the data, there will be a period of waiting, the situation leads to the solution page UI data latency. It had to do a preparation.

At last

Andrews advanced development interview is not easy to grasp the knowledge points, so we have to see more to learn

After reading this knowledge would also like to have more of a small partner, you can see I tidied senior interview topics , for everyone to share

If you have more content can also be issued to, we learn together and progress together!
Andrews how to master the advanced development interview knowledge?  Cache focus in this!

Guess you like

Origin blog.51cto.com/14606040/2465680