     
     public func setData(getData : @autoclosure () -> NSData?, key : String) {
         dispatch_async(cacheQueue, {
-            let path = self.pathForKey(key)
-            var error: NSError? = nil
-            if let data = getData() {
-                let fileManager = NSFileManager.defaultManager()
-                let previousAttributes : NSDictionary? = fileManager.attributesOfItemAtPath(path, error: nil)
-                let success = data.writeToFile(path, options: NSDataWritingOptions.AtomicWrite, error:&error)
-                if (!success) {
-                    NSLog("Failed to write key \(key) with error \(error!)")
-                }
-                if let attributes = previousAttributes {
-                    self.size -= attributes.fileSize()
-                }
-                self.size += data.length
-                self.controlCapacity()
-            } else {
-                NSLog("Failed to get data for key \(key)")
-            }
+            self.setDataSync(getData, key: key)
         })
     }
     

            let path = self.pathForKey(key)
            let fileManager = NSFileManager.defaultManager()
            if (!self.updateDiskAccessDateAtPath(path) && !fileManager.fileExistsAtPath(path)){
                self.setData(image.hnk_data(), key: key)
            }
        })
    }

        }
    }
    
    public func setDataSync(getData : @autoclosure () -> NSData?, key : String) {
        let path = self.pathForKey(key)
        var error: NSError? = nil
        if let data = getData() {
            let fileManager = NSFileManager.defaultManager()
            let previousAttributes : NSDictionary? = fileManager.attributesOfItemAtPath(path, error: nil)
            let success = data.writeToFile(path, options: NSDataWritingOptions.AtomicWrite, error:&error)
            if (!success) {
                NSLog("Failed to write key \(key) with error \(error!)")
            }
            if let attributes = previousAttributes {
                self.size -= attributes.fileSize()
            }
            self.size += data.length
            self.controlCapacity()
        } else {
            NSLog("Failed to get data for key \(key)")
        }
    }
    
    private func updateDiskAccessDateAtPath(path : String) -> Bool {
        let fileManager = NSFileManager.defaultManager()
        let now = NSDate()
        var error : NSError?
        let success = fileManager.setAttributes([NSFileModificationDate : now], ofItemAtPath: path, error: &error)
        if !success {
            NSLog("Failed to update access date with error \(error!)")
        }
        return success;
    }
    
    private func removeFileAtPath(path:String) {
