   
   private func calculateSize() {
     size = 0
-    let cachePath = path
-    if let contents = fileManager.contentsOfDirectoryAtPath(cachePath, error: nil) as? [String] {
+    if let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as? [String] {
       for pathComponent in contents {
-        let path = cachePath.stringByAppendingPathComponent(pathComponent)
-        if let attributes : NSDictionary = fileManager.attributesOfItemAtPath(path, error: nil) {
+        let filePath = path.stringByAppendingPathComponent(pathComponent)
+        if let attributes: NSDictionary = fileManager.attributesOfItemAtPath(filePath, error: nil) {
           size += attributes.fileSize()
         }
       }

  }
  
  private func controlCapacity() {
    if size <= capacity {
      return
    }
    
    let cachePath = path
    enumerateContentsOfDirectorySortedByAscendingModificationDateAtPath(cachePath) { (URL, _, inout stop: Bool) in
      if let path = URL.path {
        self.removeFileAtPath(path)
        stop = self.size <= self.capacity
      }
    }
  }
  
  private func setDataSync(data: NSData, key : String) {
    let path = pathForKey(key)
    let previousAttributes : NSDictionary? = fileManager.attributesOfItemAtPath(path, error: nil)
    let success = data.writeToFile(path, options: NSDataWritingOptions.AtomicWrite, error: nil)
    if !success {
      Logger.log("Failed to write key \(key) on the disk cache")
    }
    
    if let attributes = previousAttributes {
      size -= attributes.fileSize()
    }
    size += UInt64(data.length)
    
    controlCapacity()
  }
  
  private func updateDiskAccessDateAtPath(path : String) -> Bool {
    return fileManager.setAttributes([
      NSFileModificationDate: NSDate()
    ], ofItemAtPath: path, error: nil)
  }
  
  private func removeFileAtPath(path: String) {
    if let attributes : NSDictionary = fileManager.attributesOfItemAtPath(path, error: nil) {
      let fileSize = attributes.fileSize()
      if fileManager.removeItemAtPath(path, error: nil) {
        size -= fileSize
      }
    }
  }
}

private func enumerateContentsOfDirectorySortedByAscendingModificationDateAtPath(path: String, usingBlock block : (NSURL, Int, inout Bool) -> Void) {
  let property = NSURLContentModificationDateKey
  let directoryURL = NSURL(fileURLWithPath: path)
  if directoryURL == nil { return }
  var error : NSError?
  if let contents = NSFileManager.defaultManager().contentsOfDirectoryAtURL(directoryURL!, includingPropertiesForKeys: [property], options: NSDirectoryEnumerationOptions.allZeros, error: &error) as? [NSURL] {
    
    let sortedContents = contents.sorted({(URL1 : NSURL, URL2 : NSURL) -> Bool in
      var value1 : AnyObject?
      if !URL1.getResourceValue(&value1, forKey: property, error: nil) {
        return true
      }
      var value2 : AnyObject?
      if !URL2.getResourceValue(&value2, forKey: property, error: nil) {
        return false
      }

  }
  
  private lazy var cacheQueue : dispatch_queue_t = {
    return dispatch_queue_create(CarlosGlobals.QueueNamePrefix + self.path.lastPathComponent, nil)
  }()
  
  public func onMemoryWarning() {}
