| 234 | } |
| 235 | |
| 236 | folly::coro::Task<Result<AllocatedHandle>> RAMCacheComponent::allocate( |
| 237 | Key key, uint32_t size, uint32_t creationTime, uint32_t ttlSecs) { |
| 238 | stats_->allocate_.throughput_.calls_.inc(); |
| 239 | // Latency is not tracked here; CacheAllocator already tracks it via |
| 240 | // stats_.allocateLatency_. See getStats(). |
| 241 | |
| 242 | try { |
| 243 | auto implHandle = cache_->allocate( |
| 244 | defaultPool_, key, size + sizeof(RAMCacheItem), ttlSecs, creationTime); |
| 245 | if (!implHandle) { |
| 246 | stats_->allocate_.throughput_.errors_.inc(); |
| 247 | co_return makeError( |
| 248 | Error::Code::NO_SPACE, |
| 249 | fmt::format("could not find room in cache for {}", key)); |
| 250 | } |
| 251 | stats_->allocate_.throughput_.successes_.inc(); |
| 252 | co_return tryCreateHandle<AllocatedHandle>( |
| 253 | *this, *RAMCacheItem::init(implHandle.get())); |
| 254 | } catch (const exception::RefcountOverflow& ro) { |
| 255 | XLOG(DFATAL) << "ERROR: refcount overflow in allocate which shouldn't be " |
| 256 | "possible (nobody else can access the item)"; |
| 257 | stats_->allocate_.throughput_.errors_.inc(); |
| 258 | co_return makeError(Error::Code::INC_REF_FAILED, ro.what()); |
| 259 | } catch (const std::exception& e) { |
| 260 | stats_->allocate_.throughput_.errors_.inc(); |
| 261 | co_return makeError(Error::Code::INVALID_ARGUMENTS, e.what()); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | folly::coro::Task<UnitResult> RAMCacheComponent::insert( |
| 266 | AllocatedHandle&& handle) { |