-
IRHTTPCache is a copy project from KTVHTTPCache.
-
IRHTTPCache is a powerful media cache framework. It can cache HTTP request, and very suitable for media resources.
-
A usage case is using IRHTTPCache combine with the video player(IRPlayer) for cache.
- Support Swift.
- Thread safety.
- Logging system, Support for console and file output.
- Accurate view caching information.
- Provide different levels of interface.
- Adjust the download configuration.
- Including demo
- AVPlayer
- (IRPlayer)
- Git clone this project.
- Copy this project into your own project.
- Add the .xcodeproj into you project and link it as an embed framework.
- Also, link IRCocoaHTTPServer as an embed framework.
- You can remove the
demo
andScreenShots
folder.
- Add
pod 'IRHTTPCache'
in thePodfile
pod install
let _: () = { () -> () in
self.setupHTTPCache()
}()
...
func setupHTTPCache() {
IRHTTPCache.logSetConsoleLogEnable(true)
do {
try IRHTTPCache.proxyStart()
NSLog("Proxy Start Success");
} catch {
NSLog("Proxy Start Failure");
}
IRHTTPCache.encodeSetURLConverter { (URL) -> URL? in
NSLog("URL Filter reviced URL")
return URL
}
IRHTTPCache.downloadSetUnacceptableContentTypeDisposer { (URL, contentType) -> Bool in
NSLog("Unsupport Content-Type Filter reviced URL")
return false
}
}
- Generated proxy URL.
IRHTTPCache.proxyURL(withOriginalURL: originalURL)
- Start proxy.
[IRHTTPCache proxyStart:&error];
- Generated proxy URL.
NSURL *proxyURL = [IRHTTPCache proxyURLWithOriginalURL:originalURL];
AVPlayer *player = [AVPlayer playerWithURL:proxyURL];
- Get the complete cache file URL if existed.
NSURL *completeCacheFileURL= [IRHTTPCache cacheCompleteFileURLWithURL:originalURL];
- Set the URL filter processing mapping relationship.
[IRHTTPCache encodeSetURLConverter:^NSURL *(NSURL *URL) {
return URL;
}];
- Download Configuration
// Timeout interval.
[IRHTTPCache downloadSetTimeoutInterval:30];
// Accept Content-Type.
[IRHTTPCache downloadSetAcceptableContentTypes:contentTypes];
// Set unsupport Content-Type filter.
[IRHTTPCache downloadSetUnacceptableContentTypeDisposer:^BOOL(NSURL *URL, NSString *contentType) {
return NO;
}];
// Additional headers.
[IRHTTPCache downloadSetAdditionalHeaders:headers];
// Whitelist headers.
[IRHTTPCache downloadSetWhitelistHeaderKeys:headers];
- Log.
// Console.
[IRHTTPCache logSetConsoleLogEnable:YES];
// File.
[IRHTTPCache logSetRecordLogEnable:YES];
NSString *logFilePath = [IRHTTPCache logRecordLogFilePath];
Demo Main Page | Demo1 |
---|---|