Android four image cache (Imageloader,picasso,glide,fresco) principle, feature comparison

Source: Internet
Author: User
Tags webp

Four big picture cache basic information


Universal Imageloader is an early open source image cache that has been used by many applications in the early days.

Picasso is a Square open source project, and his leader is Jakewharton, so it is widely known.

Glide is an open source project for Google employees and is used by some Google apps to be featured on Google I/O last year, but there is little domestic data.

Fresco is an open source image cache for Facebook in the first half of this year, with key features including:
(1) Two memory buffers plus Native cache make up level three cache

(2) Support streaming, can be similar to the fuzzy progressive display image on the page

(3) Better support for multi-frame animated pictures, such as Gif, WebP

Since Fresco has not released the official 1.0 version, but also has not too much time familiar with the Fresco source code, the contrast does not include Fresco, after the time to add the contrast

Ii. Basic Concepts

Before you make a formal comparison, let's look at some common concepts of image caching:
(1) Requestmanager: Request generation and Management module

(2) Engine: Engines section, responsible for creating tasks (get data), and scheduling execution

(3) Getdatainterface: Data acquisition Interface, responsible for obtaining data from various data sources.
For example, memorycache from the memory cache to obtain data, diskcache from the local cache to obtain data, the downloader from the network to obtain data and so on.

(4) Displayer: resource (image) display for displaying or manipulating resources.
For example ImageView, these image caches not only support ImageView, but also support other View and virtual displayer concepts.

(5) Processor resources (image) processor
Responsible for processing resources, such as rotation, compression, interception and so on.

The above concepts may be different in different picture caches, such as Displayer in Imageloader called Imageaware, in Picasso and Glide called Target.

Third, common advantages

1. Easy to use
Can be achieved through a code to achieve picture acquisition and display.

2. High degree of configuration and high adaptability
Picture Cache Downloader (retry mechanism), decoder, monitor, processor, memory cache, local cache, thread pool, cache algorithm, etc. can be easily configured.

High degree of adaptability, according to the system performance initialization cache configuration, System information changes after the dynamic adjustment strategy.
For example, according to the number of CPU cores to determine the maximum number of concurrent, based on the available memory to determine the size of memory cache, network state changes when the maximum number of concurrency.

3. Multilevel caching
Have at least two levels of cache, increasing the speed of picture loading.

4. Support Multiple data sources
Support multiple data sources, network, local, resource, Assets, etc.

5. Support multiple Displayer
Not only supports ImageView, but also supports other View and virtual displayer concepts.

Other small things in common include support for animations, support for transform processing, access to EXIF information, and more.

Four, imageloader design and advantages

1. Overall design and process

Above is the overall design of the imageloader. The whole library is divided into five modules of Imageloaderengine,cache and Imagedownloader,imagedecoder,bitmapdisplayer,bitmapprocessor, of which the Cache is divided into MemoryCache and DiskCache two parts.

Simply speaking, Imageloader receives the task of loading and displaying the picture and handing it over to the Imageloaderengine,imageloaderengine distribution task to the specific thread pool to execute, the task through the Cache and Imagedownloader Get the picture, the middle may go through bitmapprocessor and imagedecoder processing, the final conversion to bitmap to Bitmapdisplayer in Imageaware display.

2. Imageloader Advantages

(1) Support Download Progress monitoring

(2) You can pause picture loading in View scrolling
The Pauseonscrolllistener interface lets you pause picture loading in View scrolling.

(3) The default implementation of a variety of memory cache algorithm These image caches can be configured cache algorithm, but imageloader default implementation of more cache algorithms, such as the Size of the largest first delete, the use of least first delete, the least recently used, advanced first Delete, the longest time to delete and so on.

(4) Support local cache file name rule definition

Five, Picasso design and advantages

1. Overall design and process

Above is the overall design of the Picasso. The whole library is divided into modules such as Dispatcher,requesthandler and downloader,picassodrawable.

Dispatcher is responsible for distributing and handling actions, including commit, pause, resume, cancel, network status changes, retry, and so on.

The simple thing is that Picasso receives the task of loading and displaying the picture, creating the Request and handing it over to the Dispatcher,dispatcher distribution task to the specific RequestHandler, the task through MemoryCache and Handler ( Data acquisition interface) to obtain a picture, the image obtained successfully through the picassodrawable display to Target.

Note that the File system section of Data above, Picasso does not have a custom local cache interface, the default use of HTTP local cache, API 9 and above using Okhttp, the following use URLConnection, so if you need to customize the local cache requires a heavy Define Downloader.

2. Picasso Advantages

(1) Self-monitoring function with statistics
Supports monitoring of image cache usage, including cache hit ratio, used memory size, saved traffic, and more.

(2) Support priority processing
Priority tasks are selected before each task is scheduled, such as when the Banner priority in the APP page is higher than the Icon.

(3) Support delay to picture size calculation complete loading

(4) Support flight mode, number of concurrent threads varies by network type
The maximum concurrency of the thread pool is automatically adjusted when the phone switches to airplane mode or network type transformation, such as WiFi maximum concurrency is 4, and 4g is 3,3g 2.
Here Picasso determines the maximum number of concurrent, not CPU cores, based on the network type.

(5) "None" local cache
No "local cache", not that there is no local cache, but Picasso itself is not implemented, to the Square of another network library okhttp to implement, the benefit is can be requested Response Header Cache-control and Expired Controls when the picture expires.

Six, Glide design and advantages

1. Overall design and process

Above is the overall design of the Glide. The entire library is divided into Requestmanager (Request manager), Engine (data acquisition engine), Fetcher (data Capture), MemoryCache (memory cache), Disklrucache, transformation (image processing), Modules such as Encoder (local cache storage), Registry (image type and parser configuration), Target (destination), and so on.

Simply speaking, Glide receives the task of loading and displaying the resource, creating the Request and handing it over to the requestmanager,request boot Engine to get the resource (via Fetcher), and get to the post transformation processing To Target.

Glide relies on the Disklrucache, Gifdecoder and other open source libraries to complete the local cache and Gif image decoding work.

2. Glide Advantages

(1) Image cache, media cache
Glide is not just a picture cache, it supports Gif, WebP, thumbnails. Even Video, so it's more like a media cache.

(2) Support priority processing

(3) Consistent with activity/fragment life cycle, support trimmemory
Glide maintains a requestmanager for each context, is consistent with the activity/fragment life cycle through fragmenttransaction, and has a corresponding Trimmemory interface implementation available for invocation.

(4) Support Okhttp, volley
Glide data is obtained by default via URLConnection and can be used with okhttp or volley. Actual Imageloader, Picasso also support Okhttp, volley.

(5) Memory-friendly
①glide's memory cache has an active design
When fetching data from the memory cache, it is not like the general implementation with get, but with remove, and then put the cached data in a soft reference to the value of Activeresources map, and count the number of references, after the completion of the picture loading is done, if the reference count is empty, it is recycled.

② memory cache for smaller images
Glide as a federated key with URLs, View_width, view_height, screen resolution, and so on, the processed picture is cached in the memory cache instead of the original image to save size

③ is consistent with the activity/fragment life cycle, supporting trimmemory

④ picture defaults to default rgb_565 instead of argb_888
Although the sharpness is poor, but the picture is smaller, can also be configured to argb_888.

Other: Glide can support URL expiration by signature or not using local cache

Vii. Summary


Generally speaking, the function of Imageloader and the length of the agent are easy to understand.

Although the Picasso code is only in one package, there is no strict package distinction, but the code is simple, logical and clear, one or two hours can be called in-depth understanding of the end.

Glide is powerful, but the code is large and the flow is complicated. In the case of a deeper grasp of the recommended use, lest there is a problem difficult to solve.

Android four image cache (Imageloader,picasso,glide,fresco) principle, feature comparison

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.