             cache                     : createImageCacheAdapter() ,
             cacheDataLifeTimeInSeconds: self.dynamicType.cacheDataLifeTimeInSeconds
         )
-        
+
         let loader = jSmartDataLoaderWithCache(args)
-        
+
         return bindTrySequenceOfAsyncs(loader, { (error: NSError) -> AsyncTypes<UIImage, NSError>.Async in
-            
+
             let resultError = CacheLoadImageError(nativeError: error)
             return async(error: resultError)
         })
     }
-    
+
     private static var cacheDataLifeTimeInSeconds: NSTimeInterval {
-        
+
         let dbInfoByNames = Caches.sharedCaches().dbInfo.dbInfoByNames
         let info = dbInfoByNames.infoByDBName(Caches.thumbnailDBName())!
         return info.timeToLiveInHours * 3600.0
     }
-    
+
     final private class ImageCacheAdapter : CacheAdapter {
-        
+
         init() {
-            
+
             let cacheFactory = { () -> CacheDB in
                 return Caches.sharedCaches().createThumbnailDB()
             }
-            
+
             super.init(cacheFactory: cacheFactory, cacheQueueName: cacheQueueName)
         }
-        
+
         override func loaderToSetData(data: NSData, forKey key: String) -> AsyncTypes<Void, NSError>.Async {
-            
+
             let loader = super.loaderToSetData(data, forKey:key)
             return Transformer.transformLoadersType1(loader, transformer: balanced)
         }
-        
+
         override func cachedDataLoaderForKey(key: String) -> AsyncTypes<(date: NSDate, data: NSData), NSError>.Async {
-            
+
             let loader = super.cachedDataLoaderForKey(key)
             return Transformer.transformLoadersType2(loader, transformer: balanced)
         }
     }
-    
+
     private func createImageCacheAdapter() -> ImageCacheAdapter {
 
         let result = ImageCacheAdapter()

        class Singleton  {
            static let sharedInstance = NSLock()
        }
        
        Singleton.sharedInstance.lock()
        let result = UIImage(data: data)
        Singleton.sharedInstance.unlock()

//limit sqlite number of threads
private let cacheBalancer = LimitedLoadersQueue<StrategyFifo<Transformer.PackedType, NSError>>()

private func balanced(loader: AsyncTypes<Transformer.PackedType, NSError>.Async) -> AsyncTypes<Transformer.PackedType, NSError>.Async {

    return cacheBalancer.balancedLoaderWithLoader(loader, barrier:false)
}
