網(wǎng)絡(luò)請求流程.png
NetTask:有緩存就直接返回,沒有就創(chuàng)建請求任務(wù)。
manager:負(fù)責(zé)發(fā)起網(wǎng)絡(luò),處理網(wǎng)絡(luò)回來數(shù)據(jù)轉(zhuǎn)發(fā)。
request:專門負(fù)責(zé)網(wǎng)絡(luò)請求操作,可以AFNetWorking。
cache:負(fù)責(zé)緩存功能。
utility:提供數(shù)據(jù)加解密、解壓縮。
發(fā)起請求:
1、NetTask通過cache判斷緩存,有就馬上返回;沒有就執(zhí)行第二步。
2、NetTask通過utility加密數(shù)據(jù),創(chuàng)建NetObject網(wǎng)絡(luò)對象給manager。
3、manager強行持有NetObject網(wǎng)絡(luò)對象,然后通過request開始網(wǎng)絡(luò)請求。
網(wǎng)絡(luò)回來:
1、request把data給manager。
2、manager通過utility、cache把data解密、緩存。
3、manager通過NetObject網(wǎng)絡(luò)對象,把加工后的data返回給VC。
cache:可以使用策略,F(xiàn)IFO、LRU(NSCache默認(rèn))、LFU