 import Foundation
 import Darwin
 
+public enum CacheType {
+    case FIFO
+    case LRU
+}
+
+private let DefaultCacheType : CacheType = .FIFO
+
 public extension WKInterfaceImage {
-    public func setCachedImage(image : UIImage) {
-        let imageData = UIImageJPEGRepresentation(image, 0.6)
-        ImageCache.setCachedImageData(imageData, cachedBlock: { (key) -> Void in
-            self.setImageNamed(key)
-        })
+    public func setCachedImage(image : UIImage, compression : CGFloat = 0.6, cacheType : CacheType = DefaultCacheType) -> String {
+        return setCachedImageData(UIImageJPEGRepresentation(image, compression), cacheType: cacheType)
     }
     
-    public func setCachedImageData(imageData : NSData) {
-        ImageCache.setCachedImageData(imageData, cachedBlock: { (key) -> Void in
+    public func setCachedImageData(imageData : NSData, cacheType : CacheType = DefaultCacheType) -> String {
+        return ImageCache.setCachedImageData(imageData, cacheType: cacheType, cachedBlock: { (key) -> Void in
             self.setImageNamed(key)
         })
     }

        }
    }
    
    private static let cacheKey = "de.mathiaskoehnke.wkimagecache"
    private static let lockQueue = dispatch_queue_create(cacheKey, nil)
    private static var timeStamps : NSMutableDictionary?


public extension WKInterfaceButton {
    
    public func setCachedBackgroundImage(image : UIImage, compression : CGFloat = 0.6, cacheType : CacheType = DefaultCacheType) -> String {
        return setCachedBackgroundImageData(UIImageJPEGRepresentation(image, compression), cacheType: cacheType)
    }
    
    public func setCachedBackgroundImageData(imageData : NSData, cacheType : CacheType = DefaultCacheType) -> String {
        return ImageCache.setCachedImageData(imageData, cacheType: cacheType, cachedBlock: { (key) -> Void in
            self.setBackgroundImageNamed(key)
        })
    }
