Moya http cache

Created on 4 Feb 2016  Â·  6Comments  Â·  Source: Moya/Moya

How can Moya apply http level cache ?

Most helpful comment

I know, this topic is a bit old, but if anyone still looking for "Moya" way to take control over http caching (read use plugin), I would recommend to look at my answer here.

All 6 comments

Caching would be handled by AlamoFire: https://github.com/Alamofire/Alamofire#caching (which in turn uses the system cache)

A cache is set at a system level by default but if you want to set specific sizes or handle it yourself, you can set your own cache:

let URLCache = NSURLCache(memoryCapacity: 4 * 1024 * 1024, diskCapacity: 20 * 1024 * 1024, diskPath: nil)
NSURLCache.setSharedURLCache(URLCache)

In Alamofire page : "Caching is handled on the system framework level by NSURLCache."
https://github.com/Moya/Moya/tree/master/docs : "You should not have to reference Alamofire directly."
Can I apply NSURLCache in Moya directly ?
(Thank wattson12)

Moya itself has no concept of a cache so you don't need to apply the cache in Moya directly, you also don't need to set a cache for AlamoFire since it uses the system level cache. If you set the system level NSURLCache it will be used by both libraries (though it is already set by default)

There is a good description of NSURLCache here: http://nshipster.com/nsurlcache/

(you can also set a subclass of NSURLCache if you want more customisation)

Great answer @wattson12 – thanks for answering so quickly!

I think that everything _should_ be clear now, so I'm gonna close it. 🎉 If you have any more concerns, please let me now and I will reopen the issue!

I know, this topic is a bit old, but if anyone still looking for "Moya" way to take control over http caching (read use plugin), I would recommend to look at my answer here.

Was this page helpful?
0 / 5 - 0 ratings