MCPcopy Create free account
hub / github.com/facebook/CacheLib / create

Method create

cachelib/interface/components/RAMCacheComponent.cpp:190–228  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

188}
189
190/* static */ Result<RAMCacheComponent> RAMCacheComponent::create(
191 LruAllocatorConfig&& allocConfig,
192 PoolConfig&& poolConfig,
193 PersistenceConfig persistenceConfig,
194 const LatencySamplingConfig& latencySamplingConfig) noexcept {
195 if (allocConfig.nvmConfig) {
196 return makeError(Error::Code::INVALID_CONFIG,
197 "RAMCacheComponent does not support NVM cache");
198 } else if (allocConfig.poolRebalancingEnabled()) {
199 return makeError(Error::Code::INVALID_CONFIG,
200 "RAMCacheComponent does not support pool rebalancing");
201 } else if (persistenceConfig.persist() || persistenceConfig.recover()) {
202 if (persistenceConfig.cacheDir().empty()) {
203 return makeError(Error::Code::INVALID_CONFIG,
204 "cacheDir must be set for persistence/recovery");
205 }
206 allocConfig.enableCachePersistence(std::move(persistenceConfig.cacheDir()),
207 persistenceConfig.baseAddr());
208 }
209 try {
210 auto cache = RAMCacheComponent(std::move(allocConfig), persistenceConfig,
211 latencySamplingConfig);
212 auto ids = cache.cache_->getPoolIds();
213 if (!ids.empty()) {
214 // Pool was restored from shared memory, just look up its ID
215 XCHECK_EQ(ids.size(), 1UL);
216 cache.defaultPool_ = *ids.begin();
217 } else {
218 // Add a default pool that will be used for all allocations
219 cache.defaultPool_ = cache.cache_->addPool(
220 poolConfig.name_, poolConfig.size_, poolConfig.allocSizes_,
221 poolConfig.mmConfig_, poolConfig.rebalanceStrategy_,
222 poolConfig.resizeStrategy_, poolConfig.ensureProvisionable_);
223 }
224 return cache;
225 } catch (const std::exception& e) {
226 return makeError(Error::Code::INVALID_CONFIG, e.what());
227 }
228}
229
230LruAllocator& RAMCacheComponent::get() const noexcept { return *cache_; }
231

Callers

nothing calls this directly

Calls 11

baseAddrMethod · 0.80
whatMethod · 0.80
RAMCacheComponentClass · 0.70
persistMethod · 0.45
recoverMethod · 0.45
emptyMethod · 0.45
getPoolIdsMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
addPoolMethod · 0.45

Tested by

no test coverage detected