MCPcopy Index your code
hub / github.com/facebook/CacheLib / insert

Method insert

cachelib/interface/components/RAMCacheComponent.cpp:265–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265folly::coro::Task<UnitResult> RAMCacheComponent::insert(
266 AllocatedHandle&& handle) {
267 stats_->insert_.throughput_.calls_.inc();
268
269 if (!handle) {
270 stats_->insert_.throughput_.errors_.inc();
271 co_return makeError(Error::Code::INVALID_ARGUMENTS,
272 "empty AllocatedHandle");
273 }
274
275 auto latencyGuard = stats_->insert_.latency_.start();
276 try {
277 auto* implItem = getImplItemFromHandle(handle);
278 auto implHandle = cache_->acquire(implItem);
279 if (!implHandle) {
280 XLOG(DFATAL) << "Evicting item that hasn't been inserted";
281 stats_->insert_.throughput_.errors_.inc();
282 co_return makeError(Error::Code::INSERT_FAILED, "item is being evicted");
283 }
284 if (!cache_->insert(implHandle)) {
285 stats_->insert_.throughput_.errors_.inc();
286 co_return makeError(Error::Code::ALREADY_INSERTED,
287 "key already exists in cache");
288 }
289 } catch (const std::invalid_argument& ia) {
290 // Should only happen when implHandle->isAccessible() == true
291 XLOG(DFATAL) << "Double-insert from the same allocated handle - did we "
292 "forget to release the AllocatedHandle after inserting?";
293 stats_->insert_.throughput_.errors_.inc();
294 co_return makeError(Error::Code::ALREADY_INSERTED, ia.what());
295 } catch (const std::exception& e) {
296 stats_->insert_.throughput_.errors_.inc();
297 co_return makeError(Error::Code::INSERT_FAILED, e.what());
298 }
299
300 stats_->insert_.throughput_.successes_.inc();
301 auto _ = std::move(handle);
302 co_return folly::unit;
303}
304
305folly::coro::Task<Result<std::optional<AllocatedHandle>>>
306RAMCacheComponent::insertOrReplace(AllocatedHandle&& handle) {

Callers 5

printExtraOpCountersFunction · 0.45
CO_TEST_FFunction · 0.45
CO_TYPED_TESTFunction · 0.45
CO_TYPED_TESTFunction · 0.45
TYPED_TESTFunction · 0.45

Calls 5

getImplItemFromHandleFunction · 0.85
whatMethod · 0.80
incMethod · 0.45
startMethod · 0.45
acquireMethod · 0.45

Tested by 4

CO_TEST_FFunction · 0.36
CO_TYPED_TESTFunction · 0.36
CO_TYPED_TESTFunction · 0.36
TYPED_TESTFunction · 0.36