Link: http://keegan-lee.diandian.com/post/2012-12-06/40047548955
If you need to obtain the same image from the network every time you load it, the cost is too high. Therefore, you only need to obtain the same image from the network once, and then cache it locally. Then, load the same image from the cache. Reading images from the memory cache is the fastest, but because the memory capacity is limited, it is best to add the File Cache. The file cache space is not infinitely large. The larger the capacity, the lower the reading efficiency. Therefore, you can set a limited size such as 10 MB or a limited storage time such as one day.
Therefore, the image loading process should be:
1. obtain from the memory cache first. If the result is obtained, return. If the result is not obtained, proceed to the next step;
2. obtain from the File Cache. If the result is obtained, it is returned and updated to the memory cache. If the result is not obtained, proceed to the next step;
3. Download images from the network and update them to the memory cache and file cache.
Next we will look at the memory cache class: imagememorycache
| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
public
class
ImageMemoryCache { |