@@ -107,7 +107,10 @@ func noCompressionExample() {
107107 fmt .Printf ("📊 Original data size: %d bytes\n " , len (largeData ))
108108
109109 // Store and retrieve
110- cache .Set ("large_data" , largeData , 5 * time .Minute )
110+ if err := cache .Set ("large_data" , largeData , 5 * time .Minute ); err != nil {
111+ log .Printf ("Error setting cache: %v" , err )
112+ return
113+ }
111114
112115 retrieved , found := cache .Get ("large_data" )
113116 if ! found {
@@ -141,8 +144,14 @@ func gzipCompressionExample() {
141144 fmt .Printf ("📊 JSON data size: %d bytes\n " , len (largeData ))
142145
143146 // Store and retrieve large JSON
144- cache .Set ("large_json" , largeData , 5 * time .Minute )
145- cache .Set ("large_user" , user , 5 * time .Minute )
147+ if err := cache .Set ("large_json" , largeData , 5 * time .Minute ); err != nil {
148+ log .Printf ("Error setting JSON cache: %v" , err )
149+ return
150+ }
151+ if err := cache .Set ("large_user" , user , 5 * time .Minute ); err != nil {
152+ log .Printf ("Error setting user cache: %v" , err )
153+ return
154+ }
146155
147156 // Retrieve and verify
148157 retrievedJSON , found := cache .Get ("large_json" )
@@ -192,7 +201,10 @@ func deflateCompressionExample() {
192201 repeatedText := strings .Repeat ("This is a test string that repeats many times to demonstrate compression efficiency. " , 1000 )
193202 fmt .Printf ("📊 Repetitive text size: %d bytes\n " , len (repeatedText ))
194203
195- cache .Set ("repetitive_text" , repeatedText , 5 * time .Minute )
204+ if err := cache .Set ("repetitive_text" , repeatedText , 5 * time .Minute ); err != nil {
205+ log .Printf ("Error setting repetitive text cache: %v" , err )
206+ return
207+ }
196208
197209 retrieved , found := cache .Get ("repetitive_text" )
198210 if ! found {
@@ -233,11 +245,17 @@ func compressionThresholdExample() {
233245
234246 // Test with small data (should not be compressed)
235247 smallData := strings .Repeat ("small" , 50 ) // ~250 bytes
236- cache .Set ("small_data" , smallData , time .Minute )
248+ if err := cache .Set ("small_data" , smallData , time .Minute ); err != nil {
249+ log .Printf ("Error setting small data cache: %v" , err )
250+ continue
251+ }
237252
238253 // Test with large data (should be compressed if above threshold)
239254 largeData := strings .Repeat ("large data for compression testing " , 100 ) // ~3400 bytes
240- cache .Set ("large_data" , largeData , time .Minute )
255+ if err := cache .Set ("large_data" , largeData , time .Minute ); err != nil {
256+ log .Printf ("Error setting large data cache: %v" , err )
257+ continue
258+ }
241259
242260 // Retrieve both
243261 smallRetrieved , _ := cache .Get ("small_data" )
@@ -255,7 +273,9 @@ func compressionThresholdExample() {
255273 fmt .Printf (" ❌ Data integrity failed\n " )
256274 }
257275
258- cache .Close ()
276+ if err := cache .Close (); err != nil {
277+ log .Printf ("Error closing cache: %v" , err )
278+ }
259279 }
260280}
261281
@@ -270,14 +290,23 @@ func performanceComparisonExample() {
270290 fmt .Printf (" Testing %d operations without compression...\n " , iterations )
271291 start := time .Now ()
272292
273- uncompressedCache , _ := obcache .New (obcache .NewDefaultConfig ().WithMaxEntries (200 ))
293+ uncompressedCache , err := obcache .New (obcache .NewDefaultConfig ().WithMaxEntries (200 ))
294+ if err != nil {
295+ log .Printf ("Error creating uncompressed cache: %v" , err )
296+ return
297+ }
274298 for i := 0 ; i < iterations ; i ++ {
275299 key := fmt .Sprintf ("test_%d" , i )
276- uncompressedCache .Set (key , testData , time .Hour )
300+ if err := uncompressedCache .Set (key , testData , time .Hour ); err != nil {
301+ log .Printf ("Error setting uncompressed cache key %s: %v" , key , err )
302+ continue
303+ }
277304 _ , _ = uncompressedCache .Get (key )
278305 }
279306 uncompressedTime := time .Since (start )
280- uncompressedCache .Close ()
307+ if err := uncompressedCache .Close (); err != nil {
308+ log .Printf ("Error closing uncompressed cache: %v" , err )
309+ }
281310
282311 // Test with compression
283312 fmt .Printf (" Testing %d operations with gzip compression...\n " , iterations )
@@ -290,15 +319,24 @@ func performanceComparisonExample() {
290319 Algorithm : compression .CompressorGzip ,
291320 MinSize : 1000 ,
292321 })
293- compressedCache , _ := obcache .New (config )
322+ compressedCache , err := obcache .New (config )
323+ if err != nil {
324+ log .Printf ("Error creating compressed cache: %v" , err )
325+ return
326+ }
294327
295328 for i := 0 ; i < iterations ; i ++ {
296329 key := fmt .Sprintf ("test_%d" , i )
297- compressedCache .Set (key , testData , time .Hour )
330+ if err := compressedCache .Set (key , testData , time .Hour ); err != nil {
331+ log .Printf ("Error setting compressed cache key %s: %v" , key , err )
332+ continue
333+ }
298334 _ , _ = compressedCache .Get (key )
299335 }
300336 compressedTime := time .Since (start )
301- compressedCache .Close ()
337+ if err := compressedCache .Close (); err != nil {
338+ log .Printf ("Error closing compressed cache: %v" , err )
339+ }
302340
303341 // Results
304342 fmt .Printf ("\n 📊 Performance Results:\n " )
0 commit comments