     }
   }
   
+  private func folderCreate() {
+    let path = "\(config.cacheRootDirectory)\(config.cacheFolderName)/"
+    if fileManager.createDirectoryAtPath(
+      path,
+      withIntermediateDirectories: false,
+      attributes: nil,
+      error: nil){}
+  }
+  
   internal func download(url: NSURL) -> (UIImage, byteSize: Int)? {
     var err: NSError?
     var maybeImageData = NSData(contentsOfURL: url, options:.UncachedRead, error: &err)


public class PIImageCache {
  
  public init() {}
  
  public init(config: Config) {
    dispatch_semaphore_wait(memorySemaphore,DISPATCH_TIME_FOREVER)
    self.config.maxCount = config.maxCount
    self.config.maxByteSize = config.maxByteSize
    dispatch_semaphore_signal(memorySemaphore)
  }
  

  
  private var config: Config = Config()
  public class Config {
    public var maxCount : Int = 10 // 10 images
    public var maxByteSize  : Int = 3 * 1024 * 1024 //3MB
    public var usingDiskCache = true
    public var diskCacheExpireMinutes = 24 * 60 // 1 day
    public var cacheRootDirectory = NSTemporaryDirectory()
    public var cacheFolderName = "PIImageCache"
  }
  
  public func setConfig(config :Config) {
