 import SwiftyJSON
 
 enum TKTTPifierCache {
-  // TODO: Re-use TKJSONCache
-
+  private static let problemsDir = "problems"
+  private static let solutionsDir = "solutions"
   
   static func problemId(forParas paras: [String: AnyObject]) -> String? {
     let hash = inputHash(paras)

  }
  
  private static func problemId(hash: UInt) -> String? {
    
    let filePath = cacheURL("problems", filename: "\(hash)")
    
    guard let data = NSData(contentsOfURL: filePath),
          let dict = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? [String: String] else {
      return nil
    }

    return dict["id"]
  }
  
  static func save(problemId id: String, forParas paras: [String: AnyObject]) {
    let hash = inputHash(paras)
    let filePath = cacheURL("problems", filename: "\(hash)")
    
    let dict = ["id": id]
    let data = NSKeyedArchiver.archivedDataWithRootObject(dict)
    data.writeToURL(filePath, atomically: true)
    assert(problemId(forParas: paras) == id)
  }
  

    let hash = inputHash(paras)
    
    if let id = problemId(hash) {
      TKJSONCache.remove(id, directory: .Cache, subdirectory: solutionsDir)
    }
    TKJSONCache.remove("\(hash)", directory: .Cache, subdirectory: problemsDir)
  }

  static func solutionJson(forId id: String) -> JSON? {
    if let dict = TKJSONCache.read(id, directory: .Cache, subdirectory: solutionsDir) {
      return JSON(dict)
    } else {
      return nil
    }
  }
  
  static func save(solutionJson json: JSON, forId id: String) {
    guard let dict = json.dictionaryObject else {
      SGKLog.warn("TKTTPifierCache", text: "Could not turn json into dictionary. JSON: \(json)")
      return
    }
    TKJSONCache.save(id, dictionary: dict, directory: .Cache, subdirectory: solutionsDir)
  }
  
  private static func inputHash(input: [String: AnyObject]) -> UInt {
