OkHttp3.7.0 architecture and Principle Analysis, okhttp3.7.0 Architecture

Source: Internet
Author: User
Tags delete cache

OkHttp3.7.0 architecture and Principle Analysis, okhttp3.7.0 Architecture

Final Summary

Realcall.exe cute

1.dispatcher.exe cute

2. get...

3. finish the output queue to boost execution

Realcall. enqueue = dispatcher. enqueue (Async)

1. get

2. Callback

3. finish the output queue to boost execution

Interceptor

Retryfollw

Retry upon failure

Redirect to directly initiate new requests (conditional permit, reuse connection)

Bridge

Translator

ContentLength, encoding

Compression and decompression

Cookie

Header, such as User-Agent, Host, Keep-alive

Cache

Find

The returned content is changed and updated.

Delete Cache

You can also specify the directory, cache size, and logic.

Cache, with disk lru. The deletion rule is the number of requests and the number of times the cache is matched. The local database maintains two statuses: DIRTY and CLEAN. Both creation and update are based on DIRTY, implementing read/write splitting. Each status corresponds to two types of data: 1. meta2. content

CacheStrategy Factorgy generates a cache policy based on the request and responds Based on the cache policy.

Connect

HttpCodec, which encapsulates Socket with okio.

Creation principle: Find an available RealConnection in the connection pool and use its BufferedSource and BufferedSink to create an HttpCodec object.

Multiplexing: Old HTTP requests require frequent handshakes, new connections are retained, compressed, and sharded.

The onpool is managed through the Count + Mark clearing mechanism, so that useless connections can be recycled and multiple healthy keep-alive connections are maintained.

Callserver

Real Portal

Requestheader

Requestbody

Responsebody

Responsebody, and then construct a new response object based on the Response object constructed above

The core work is completed by the HttpCodec object.

Body

1. Only consume once

2. close is required

Detailed principle of cache and connection pool is not analyzed in depth

Related Article

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.