Add more documentation

This commit is contained in:
Vadym Markov
2017-05-31 21:05:35 +02:00
parent e3106ed3d4
commit ea3ea53fa1
4 changed files with 18 additions and 11 deletions
+11 -4
View File
@@ -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
+5 -5
View File
@@ -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
}
+1 -1
View File
@@ -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: ".")
+1 -1
View File
@@ -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 {