@@ -11,9 +11,12 @@ class ImageCache extends LruCache<String, List<int>> {
1111 }
1212
1313 @override
14- void entryRemoved (bool evicted, String key, List <int > oldValue, List <int >? newValue) {
14+ void entryRemoved (
15+ bool evicted, String key, List <int > oldValue, List <int >? newValue) {
1516 if (evicted) {
16- print ('Image evicted from cache: $key (${oldValue .length } bytes)' ); // ignore: avoid_print
17+ // ignore: avoid_print
18+ print (
19+ 'Image evicted from cache: $key (${oldValue .length } bytes)' ); // ignore: avoid_print
1720 } else {
1821 print ('Image replaced in cache: $key ' ); // ignore: avoid_print
1922 }
@@ -51,7 +54,8 @@ class UserProfileCache extends LruCache<int, Map<String, dynamic>> {
5154 }
5255
5356 @override
54- void entryRemoved (bool evicted, int key, Map <String , dynamic > oldValue, Map <String , dynamic >? newValue) {
57+ void entryRemoved (bool evicted, int key, Map <String , dynamic > oldValue,
58+ Map <String , dynamic >? newValue) {
5559 if (evicted) {
5660 print ('User profile evicted: ${oldValue ['name' ]}' ); // ignore: avoid_print
5761 }
@@ -83,12 +87,18 @@ Future<void> main() async {
8387 print ('\n Cache after adding 4th item:' ); // ignore: avoid_print
8488 print ('Size: ${await basicCache .size ()}' ); // ignore: avoid_print
8589 print ('Keys: ${await basicCache .keys ()}' ); // ignore: avoid_print
86- print ('Hit rate: ${basicCache .hitRate ().toStringAsFixed (1 )}%' ); // ignore: avoid_print
90+ // ignore: avoid_print
91+ print (
92+ 'Hit rate: ${basicCache .hitRate ().toStringAsFixed (1 )}%' ); // ignore: avoid_print
8793
8894 // Check if items exist
8995 print ('\n Checking if items exist:' ); // ignore: avoid_print
90- print ('key1 exists: ${await basicCache .containsKey ('key1' )}' ); // ignore: avoid_print
91- print ('key2 exists: ${await basicCache .containsKey ('key2' )}' ); // ignore: avoid_print // Should be false (evicted)
96+ // ignore: avoid_print
97+ print (
98+ 'key1 exists: ${await basicCache .containsKey ('key1' )}' ); // ignore: avoid_print
99+ // ignore: avoid_print
100+ print (
101+ 'key2 exists: ${await basicCache .containsKey ('key2' )}' ); // ignore: avoid_print // Should be false (evicted)
92102
93103 print ('\n === Image Cache Example ===\n ' ); // ignore: avoid_print
94104
@@ -100,9 +110,14 @@ Future<void> main() async {
100110 final image2 = await imageCache.get ('image2.jpg' );
101111 final image3 = await imageCache.get ('image3.jpg' );
102112
103- print ('Loaded ${image1 ?.length ?? 0 } bytes for image1.jpg' ); // ignore: avoid_print
104- print ('Loaded ${image2 ?.length ?? 0 } bytes for image2.jpg' ); // ignore: avoid_print
105- print ('Loaded ${image3 ?.length ?? 0 } bytes for image3.jpg' ); // ignore: avoid_print
113+ // ignore: avoid_print
114+ print ('Loaded ${image1 ?.length ?? 0 } bytes for image1.jpg' );
115+ // ignore: avoid_print
116+ print (
117+ 'Loaded ${image2 ?.length ?? 0 } bytes for image2.jpg' ); // ignore: avoid_print
118+ // ignore: avoid_print
119+ print (
120+ 'Loaded ${image3 ?.length ?? 0 } bytes for image3.jpg' ); // ignore: avoid_print
106121
107122 // Access image1 again to make it most recently used
108123 await imageCache.get ('image1.jpg' );
@@ -142,7 +157,9 @@ Future<void> main() async {
142157
143158 print ('\n User cache statistics:' ); // ignore: avoid_print
144159 print ('Size: ${await userCache .size ()}' ); // ignore: avoid_print
145- print ('Hit rate: ${userCache .hitRate ().toStringAsFixed (1 )}%' ); // ignore: avoid_print
160+ // ignore: avoid_print
161+ print (
162+ 'Hit rate: ${userCache .hitRate ().toStringAsFixed (1 )}%' ); // ignore: avoid_print
146163 print ('Create count: ${userCache .createCount ()}' ); // ignore: avoid_print
147164
148165 print ('\n === Cache Resize Example ===\n ' ); // ignore: avoid_print
@@ -188,10 +205,15 @@ Future<void> main() async {
188205 }
189206
190207 stopwatch.stop ();
191-
192- print ('Performance test completed in ${stopwatch .elapsedMilliseconds }ms' ); // ignore: avoid_print
193- print ('Operations: ${perfCache .putCount () + perfCache .hitCount () + perfCache .missCount ()}' ); // ignore: avoid_print
194- print ('Hit rate: ${perfCache .hitRate ().toStringAsFixed (1 )}%' ); // ignore: avoid_print
208+ // ignore: avoid_print
209+ print (
210+ 'Performance test completed in ${stopwatch .elapsedMilliseconds }ms' ); // ignore: avoid_print
211+ // ignore: avoid_print
212+ print (
213+ 'Operations: ${perfCache .putCount () + perfCache .hitCount () + perfCache .missCount ()}' ); // ignore: avoid_print
214+ // ignore: avoid_print
215+ print (
216+ 'Hit rate: ${perfCache .hitRate ().toStringAsFixed (1 )}%' ); // ignore: avoid_print
195217
196218 print ('\n === Cache Statistics ===\n ' ); // ignore: avoid_print
197219
0 commit comments