| 90 | } |
| 91 | |
| 92 | folly::coro::Task<UnitResult> insert(AllocatedHandle&& handle) override { |
| 93 | auto itemIt = findAllocatedItem(handle.get()); |
| 94 | if (itemIt == allocatedItems_.end()) { |
| 95 | co_return makeError(Error::Code::INVALID_ARGUMENTS, |
| 96 | "item was not allocated"); |
| 97 | } |
| 98 | |
| 99 | auto [_, inserted] = cachedItems_.try_emplace(handle->getKey(), *itemIt); |
| 100 | if (!inserted) { |
| 101 | co_return makeError(Error::Code::ALREADY_INSERTED, "duplicate key"); |
| 102 | } |
| 103 | |
| 104 | allocatedItems_.erase(itemIt); |
| 105 | releaseHandle(std::move(handle)); |
| 106 | co_return folly::unit; |
| 107 | } |
| 108 | |
| 109 | folly::coro::Task<Result<std::optional<AllocatedHandle>>> insertOrReplace( |
| 110 | AllocatedHandle&& handle) override { |