Latest 0.2.0
Homepage https://github.com/KyoheiG3/Exclusion
License MIT
Platforms ios 8.0, tvos 9.0, requires ARC
Frameworks Foundation
Authors

Build Status
Carthage compatible
Version
License
Platform

Customizable URLCache.
It can control to store the cache and to respond to the cache. So, using this with .returnCacheDataElseLoad of NSURLRequest.CachePolicy makes it ideal for caching image resources etc.

Requirements

  • Swift 4.2
  • iOS 8.0 or later
  • tvOS 9.0 or later

How to Install Exclusion

CocoaPods

Add the following to your Podfile:

pod "Exclusion"

Carthage

Add the following to your Cartfile:

github "KyoheiG3/Exclusion"

Usage

Example

Set it to URLSessionConfiguration. also, set .returnCacheDataElseLoad to requestCachePolicy of configuration if needed.

let conf = URLSessionConfiguration.default
conf.urlCache = Cache(memoryCapacity: 100 * 1024 * 1024, diskCapacity: 300 * 1024 * 1024, diskPath: "YOUR DIRECTORY PATH")
conf.requestCachePolicy = .returnCacheDataElseLoad

If also needs to control to store the cache and to respond to the cache, make an object to set up exclude. For example, you want to control more precisely with the value of Response Header.

struct Excluder: CacheExcludable {
    func canRespondCache(with httpResponse: HTTPURLResponse) -> Bool {
        return httpResponse.header.cacheControl?.noCache != false
    }

    func canStoreCache(with httpResponse: HTTPURLResponse) -> Bool {
        return httpResponse.header.cacheControl?.noStore != false
    }
}

let cache = Cache(memoryCapacity: 100 * 1024 * 1024, diskCapacity: 300 * 1024 * 1024, diskPath: "YOUR DIRECTORY PATH", excludable: Excluder())

Variable

var minimumAge: Int
  • set greater than 0 if needs to return cache forcibly, then the cache will be returned until past it.
  • if it is set less than 0, it is ignored.
  • also, it checks before the validity of response header.

Function

init(memoryCapacity: Int, diskCapacity: Int, diskPath path: String?, excludable: CacheExcludable? = default)
  • can set excludable object.

Author

Kyohei Ito

Follow me 🎉

LICENSE

Under the MIT license. See LICENSE file for details.

Latest podspec

{
    "name": "Exclusion",
    "version": "0.2.0",
    "summary": "Customizable URLCache. It can control to store the cache and to respond to the cache.",
    "homepage": "https://github.com/KyoheiG3/Exclusion",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Kyohei Ito": "[email protected]"
    },
    "swift_version": "4.2",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/KyoheiG3/Exclusion.git",
        "tag": "0.2.0"
    },
    "source_files": "Exclusion/**/*.{h,swift}",
    "requires_arc": true,
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This