Skip to content

irons163/IRHTTPCache

Repository files navigation

Build Status Platform

IRHTTPCache

  • 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.

Features

  • 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

Install

Git

  • 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.

Options

  • You can remove the demo and ScreenShots folder.

Cocoapods

  • Add pod 'IRHTTPCache' in the Podfile
  • pod install

Usage

Swift

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)

ObjC

  • 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];

Screenshots

Demo Main Page Demo1
Demo1 Demo2

About

IRHTTPCache is a powerful media cache framework. It can cache HTTP request, and very suitable for media resources.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published