| 2087 | |
| 2088 | using ObjectCache = ObjectCache<LruAllocator>; |
| 2089 | TEST(ObjectCacheTest, LruEviction) { |
| 2090 | ObjectCache::Config config; |
| 2091 | config.setCacheName("test").setCacheCapacity(1024); |
| 2092 | config.setItemDestructor( |
| 2093 | [&](ObjectCacheDestructorData data) { data.deleteObject<Foo>(); }); |
| 2094 | auto objcache = ObjectCache::create(config); |
| 2095 | |
| 2096 | for (int i = 0; i < 1025; i++) { |
| 2097 | auto foo = std::make_unique<Foo>(); |
| 2098 | foo->a = i; |
| 2099 | auto key = fmt::format("key_{}", i); |
| 2100 | objcache->insertOrReplace(key, std::move(foo)); |
| 2101 | auto found = objcache->find<Foo>(key); |
| 2102 | ASSERT_NE(nullptr, found); |
| 2103 | EXPECT_EQ(i, found->a); |
| 2104 | } |
| 2105 | auto found = objcache->find<Foo>("key_0"); |
| 2106 | EXPECT_EQ(nullptr, found); |
| 2107 | } |
| 2108 | |
| 2109 | TEST(ObjectCacheTest, LruEvictionWithSizeControl) { |
| 2110 | ObjectCache::Config config; |
nothing calls this directly
no test coverage detected