@@ -335,6 +335,70 @@ TEST(ZimArchive, cacheDontImpactReading)
335335 }
336336}
337337
338+
339+ TEST (ZimArchive, cacheChange)
340+ {
341+
342+ for (auto & testfile: getDataFilePath (" wikibooks_be_all_nopic_2017-02.zim" )) {
343+ auto archive = zim::Archive (testfile.path );
344+
345+ archive.set_dirent_cache_max_size (30 );
346+ archive.set_cluster_cache_max_size (5 );
347+
348+ auto range = archive.iterEfficient ();
349+ auto it = range.begin ();
350+ for (auto i = 0 ; i<50 && it != range.end (); i++, it++) {
351+ // Be sure to search by path to populate the dirent cache
352+ auto entry = archive.getEntryByPath (it->getPath ());
353+ auto item = entry.getItem (true );
354+ auto data = item.getData ();
355+ }
356+ EXPECT_EQ (archive.get_dirent_cache_current_size (), 30 );
357+ EXPECT_EQ (archive.get_cluster_cache_current_size (), 2 ); // Only 2 clusters in the file
358+
359+ // Reduce cache size
360+ archive.set_dirent_cache_max_size (10 );
361+ archive.set_cluster_cache_max_size (1 );
362+
363+ EXPECT_EQ (archive.get_dirent_cache_current_size (), 10 );
364+ EXPECT_EQ (archive.get_cluster_cache_current_size (), 1 );
365+
366+ for (auto i = 0 ; i<50 && it != range.end (); i++, it++) {
367+ // Be sure to search by path to populate the dirent cache
368+ auto entry = archive.getEntryByPath (it->getPath ());
369+ auto item = entry.getItem (true );
370+ auto data = item.getData ();
371+ }
372+
373+ EXPECT_EQ (archive.get_dirent_cache_current_size (), 10 );
374+ EXPECT_EQ (archive.get_cluster_cache_current_size (), 1 );
375+
376+ // Clean cache
377+ // (More than testing the value, this is needed as we want to be sure the cache is actually populated later)
378+ archive.set_dirent_cache_max_size (0 );
379+ archive.set_cluster_cache_max_size (0 );
380+
381+ EXPECT_EQ (archive.get_dirent_cache_current_size (), 0 );
382+ EXPECT_EQ (archive.get_cluster_cache_current_size (), 0 );
383+
384+ // Increase the cache
385+ archive.set_dirent_cache_max_size (20 );
386+ archive.set_cluster_cache_max_size (1 );
387+ EXPECT_EQ (archive.get_dirent_cache_current_size (), 0 );
388+ EXPECT_EQ (archive.get_cluster_cache_current_size (), 0 );
389+
390+ for (auto it = range.begin (); it != range.end (); it++) {
391+ // Be sure to search by path to populate the dirent cache
392+ auto entry = archive.getEntryByPath (it->getPath ());
393+ auto item = entry.getItem (true );
394+ auto data = item.getData ();
395+ }
396+
397+ EXPECT_EQ (archive.get_dirent_cache_current_size (), 20 );
398+ EXPECT_EQ (archive.get_cluster_cache_current_size (), 1 );
399+ }
400+ }
401+
338402TEST (ZimArchive, openDontFallbackOnNonSplitZimArchive)
339403{
340404 const char * fname = " wikibooks_be_all_nopic_2017-02.zim" ;
0 commit comments