 	
 	// MARK: Initialization
 	
-	public init(destination: CacheDestination) {
+	public init(destination: CacheDestination) throws {
 		switch destination {
 		case .temporary:
 			self.destination = URL(fileURLWithPath: NSTemporaryDirectory())

	///
	/// - Parameter fileName: of the cached data stored in the file system
	/// - Returns: the decoded cached data (if any)
	public func load<T: Cachable & Codable>(fileName: String) -> T? {
		guard
			let data = try? Data(contentsOf: destination.appendingPathComponent(fileName, isDirectory: false)),
			let decoded = try? JSONDecoder().decode(T.self, from: data)
			else { return nil }
		return decoded
	}
	
	// MARK: Private
	
	private func persist(data: Data, at url: URL) -> URL? {
		do {
			try data.write(to: url, options: [.atomicWrite])
			return url
		} catch {
			return nil
		}
	}
}


extension Cachable where Self: Codable {
	public func transform() -> Data {
		do {
			let encoded = try JSONEncoder().encode(self)
			return encoded
		} catch let error {
			fatalError("Unable to encode object: \(error)")
		}
	}
}
