@@ -27,55 +27,54 @@ struct Helper {
2727
2828let diskConfig = DiskConfig ( name: " Mix " )
2929
30- let storage = try ! Storage ( diskConfig: diskConfig)
30+ let dataStorage = try ! Storage (
31+ diskConfig: diskConfig,
32+ memoryConfig: MemoryConfig ( ) ,
33+ transformer: TransformerFactory . forData ( )
34+ )
35+
36+ let stringStorage = dataStorage. transformCodable ( ofType: String . self)
37+ let imageStorage = dataStorage. transformImage ( )
38+ let dateStorage = dataStorage. transformCodable ( ofType: Date . self)
3139
3240// We already have Codable conformances for:
3341// String, UIImage, NSData and NSDate (just for fun =)
3442
3543let string = " This is a string "
3644let image = Helper . image ( )
37- let imageWrapper = ImageWrapper ( image: image)
38- let newImage = imageWrapper. image
3945let data = Helper . data ( length: 64 )
4046let date = Date ( timeInterval: 100000 , since: Date ( ) )
4147
4248// Add objects to the cache
43- try storage . setObject ( string, forKey: " string " )
44- try storage . setObject ( imageWrapper , forKey: " imageWrapper " )
45- try storage . setObject ( data, forKey: " data " )
46- try storage . setObject ( date, forKey: " date " )
49+ try stringStorage . setObject ( string, forKey: " string " )
50+ try imageStorage . setObject ( image , forKey: " image " )
51+ try dataStorage . setObject ( data, forKey: " data " )
52+ try dateStorage . setObject ( date, forKey: " date " )
4753//
4854//// Get objects from the cache
49- let cachedString = try ? storage . object ( forKey: " string " )
55+ let cachedString = try ? stringStorage . object ( forKey: " string " )
5056print ( cachedString)
5157
52- storage. async . object ( forKey: " imageWrapper " ) { result in
53- if case . value( let imageWrapper) = result {
54- let image = imageWrapper. image
58+ imageStorage. async . object ( forKey: " image " ) { result in
59+ if case . value( let image) = result {
5560 print ( image)
5661 }
5762}
5863
59- storage. async . object ( forKey: " data " ) { result in
60- if case . value( let data) = result {
61- print ( data)
62- }
63- }
64-
65- storage. async . object ( forKey: " data " ) { result in
64+ dataStorage. async . object ( forKey: " data " ) { result in
6665 if case . value( let data) = result {
6766 print ( data)
6867 }
6968}
7069
71- storage . async . object ( ofType : Date . self , forKey: " date " ) { result in
70+ dateStorage . async . object ( forKey: " date " ) { result in
7271 if case . value( let date) = result {
7372 print ( date)
7473 }
7574}
7675
7776// Clean the cache
78- try storage . async . removeAll ( completion: { ( result) in
77+ try dataStorage . async . removeAll ( completion: { ( result) in
7978 if case . value = result {
8079 print ( " Cache cleaned " )
8180 }
0 commit comments