diff --git a/Source/Shared/BasicHybridCache.swift b/Source/Shared/BasicHybridCache.swift index 2b5c185..427b19b 100644 --- a/Source/Shared/BasicHybridCache.swift +++ b/Source/Shared/BasicHybridCache.swift @@ -13,11 +13,11 @@ public class BasicHybridCache: NSObject { public let name: String /// Cache configuration let config: Config - /// Front cache (should be less time and memory consuming) + /// Memory cache let frontStorage: MemoryStorage - // Back cache (used for content that outlives the application life-cycle) + // Disk cache (used for content that outlives the application life-cycle) var backStorage: DiskStorage - + // Disk storage path public var path: String { return backStorage.path } @@ -35,7 +35,14 @@ public class BasicHybridCache: NSObject { self.init(name: name, frontStorage: frontStorage, backStorage: backStorage, config: config) } - internal init(name: String, frontStorage: MemoryStorage, backStorage: DiskStorage, config: Config) { + /** + Creates a new instance of BasicHybridCache. + - Parameter name: A name of the cache + - Parameter frontStorage: Memory cache instance + - Parameter backStorage: Disk cache instance + - Parameter config: Cache configuration + */ + init(name: String, frontStorage: MemoryStorage, backStorage: DiskStorage, config: Config) { self.name = name self.frontStorage = frontStorage self.backStorage = backStorage diff --git a/Source/Shared/Config.swift b/Source/Shared/Config.swift index 87b8cd1..04badc9 100644 --- a/Source/Shared/Config.swift +++ b/Source/Shared/Config.swift @@ -13,7 +13,7 @@ public protocol MemoryStorageConfig { */ public protocol DiskStorageConfig { /// Maximum size of the cache storage - var maxSize: UInt { get } + var maxDiskSize: UInt { get } /// (optional) A folder to store the disk cache contents. Defaults to a prefixed directory in Caches if nil var cacheDirectory: String? { get } /// Data protection is used to store files in an encrypted format on disk and to decrypt them on demand @@ -29,8 +29,8 @@ public struct Config: MemoryStorageConfig, DiskStorageConfig { public let expiry: Expiry /// Maximum amount of items to store in memory public let maxObjectsInMemory: Int - /// Maximum size of the cache storage - public let maxSize: UInt + /// Maximum size of the disk cache storage + public let maxDiskSize: UInt /// (optional) A folder to store the disk cache contents. Defaults to a prefixed directory in Caches if nil public let cacheDirectory: String? /// Data protection is used to store files in an encrypted format on disk and to decrypt them on demand @@ -48,12 +48,12 @@ public struct Config: MemoryStorageConfig, DiskStorageConfig { */ public init(expiry: Expiry = .never, maxObjectsInMemory: Int = 0, - maxSize: UInt = 0, + maxDiskSize: UInt = 0, cacheDirectory: String? = nil, fileProtectionType: FileProtectionType = .none) { self.expiry = expiry self.maxObjectsInMemory = maxObjectsInMemory - self.maxSize = maxSize + self.maxDiskSize = maxDiskSize self.cacheDirectory = cacheDirectory self.fileProtectionType = fileProtectionType } diff --git a/Source/Shared/Storage/DiskStorage.swift b/Source/Shared/Storage/DiskStorage.swift index 5a17b35..72e7a42 100644 --- a/Source/Shared/Storage/DiskStorage.swift +++ b/Source/Shared/Storage/DiskStorage.swift @@ -27,7 +27,7 @@ public final class DiskStorage: StorageAware { - Parameter cacheDirectory: (optional) A folder to store the disk cache contents. Defaults to a prefixed directory in Caches */ public required init(name: String, config: DiskStorageConfig) { - self.maxSize = config.maxSize + self.maxSize = config.maxDiskSize let fullName = [DiskStorage.prefix, name.capitalized].joined(separator: ".") diff --git a/Source/Shared/Storage/MemoryStorage.swift b/Source/Shared/Storage/MemoryStorage.swift index 114bced..ba7f6c8 100644 --- a/Source/Shared/Storage/MemoryStorage.swift +++ b/Source/Shared/Storage/MemoryStorage.swift @@ -165,7 +165,7 @@ public final class MemoryStorage: StorageAware { - Parameter capsule: cached object wrapper - Parameter completion: Completion closure to be called when the task is done */ - func removeIfExpired(_ key: String, capsule: Capsule, completion: (() -> Void)? = nil) { + private func removeIfExpired(_ key: String, capsule: Capsule, completion: (() -> Void)? = nil) { if capsule.expired { remove(key, completion: completion) } else {