Volley源码解析之数据结构

使用2个BlockingQueue, 用于存放请求队列, 和网络队列
public class CacheDispatcher extends Thread {

    /** The queue of requests coming in for triage. */
    private final BlockingQueue<Request> mCacheQueue;

    /** The queue of requests going out to the network. */
    private final BlockingQueue<Request> mNetworkQueue;


    /** The cache to read from. */
    private final Cache mCache;
Cache 是一个接口, 网络数据缓存到DiskBasedCache本地文件中
public interface Cache {

    public void put(String key, Entry entry);
    public Entry get(String key);
}
/**
 * Cache implementation that caches files directly onto the hard disk in the specified
 * directory. The default disk usage size is 5MB, but is configurable.
 */
public class DiskBasedCache implements Cache {
    private final Map<String, CacheHeader> mEntries =
            new LinkedHashMap<String, CacheHeader>(16, .75f, true);

    @Override
    public synchronized void initialize() {
    ...
    //初始化缓存文件
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    ...
    }
}

-----------------DONE.-----------------------------------

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容