diff --git a/Haneke/Cache.swift b/Haneke/Cache.swift index 18d66011..5036ba8a 100644 --- a/Haneke/Cache.swift +++ b/Haneke/Cache.swift @@ -33,7 +33,14 @@ extension HanekeGlobals { } -public class Cache { +public class Cache: HanekeCache{ + + public override init(name: String) { + super.init(name: name) + } +} + +public class HanekeCache { let name: String @@ -76,7 +83,7 @@ public class Cache.Failer? = nil, success succeed : Fetch.Succeeder? = nil) -> Fetch { - let fetch = Cache.buildFetch(failure: fail, success: succeed) + let fetch = HanekeCache.buildFetch(failure: fail, success: succeed) if let (format, memoryCache, diskCache) = self.formats[formatName] { if let wrapper = memoryCache.objectForKey(key) as? ObjectWrapper, let result = wrapper.value as? T { fetch.succeed(result) @@ -101,7 +108,7 @@ public class Cache, formatName: String = HanekeGlobals.Cache.OriginalFormatName, failure fail : Fetch.Failer? = nil, success succeed : Fetch.Succeeder? = nil) -> Fetch { let key = fetcher.key - let fetch = Cache.buildFetch(failure: fail, success: succeed) + let fetch = HanekeCache.buildFetch(failure: fail, success: succeed) self.fetch(key: key, formatName: formatName, failure: { error in if error?.code == HanekeGlobals.Cache.ErrorCode.FormatNotFound.rawValue { fetch.fail(error) @@ -167,20 +174,20 @@ public class Cache, NSCache, DiskCache)] = [:] + var formats : [String : (Format, MemoryCacheT, DiskCacheT)] = [:] public func addFormat(format : Format) { let name = format.name let formatPath = self.formatPath(formatName: name) - let memoryCache = NSCache() - let diskCache = DiskCache(path: formatPath, capacity : format.diskCapacity) + let memoryCache = MemoryCacheT() + let diskCache = DiskCacheT(path: formatPath, capacity : format.diskCapacity) self.formats[name] = (format, memoryCache, diskCache) } // MARK: Internal lazy var cachePath: String = { - let basePath = DiskCache.basePath() + let basePath = DiskCacheT.basePath() let cachePath = (basePath as NSString).stringByAppendingPathComponent(self.name) return cachePath }() @@ -204,7 +211,7 @@ public class Cache ())?, success succeed : (T) -> ()) { + private func fetchFromDiskCache(diskCache : DiskCacheT, key: String, memoryCache : MemoryCacheT, failure fail : ((NSError?) -> ())?, success succeed : (T) -> ()) { diskCache.fetchData(key: key, failure: { error in if let block = fail { if (error?.code == NSFileReadNoSuchFileError) { diff --git a/Haneke/DiskCache.swift b/Haneke/DiskCache.swift index 746e4714..5b47bb58 100644 --- a/Haneke/DiskCache.swift +++ b/Haneke/DiskCache.swift @@ -36,7 +36,7 @@ public class DiskCache { return cacheQueue }() - public init(path: String, capacity: UInt64 = UINT64_MAX) { + public required init(path: String, capacity: UInt64 = UINT64_MAX) { self.path = path self.capacity = capacity dispatch_async(self.cacheQueue, {