@@ -158,57 +158,6 @@ class CachePool : private internal_cache::CachePoolImpl {
158
158
friend class internal_cache ::Access;
159
159
};
160
160
161
- // / Returns a cache of type `CacheType` for the specified `cache_key`.
162
- // /
163
- // / If such a cache does not already exist, or `cache_key` is empty,
164
- // / `make_cache()` is called to obtain a new such cache.
165
- // /
166
- // / \tparam CacheType Must be a class that inherits from `Cache`, or defines a
167
- // / `Cache& cache()` method.
168
- // / \param pool Cache pool, may be `nullptr` to indicate that caching is
169
- // / disabled.
170
- // / \param type_info Additional key used in looking up the cache. Has no effect
171
- // / if `cache_key` is the empty string or `pool` is `nullptr`. Set to
172
- // / `typeid(CacheType)` when calling `GetCache`, but can be any arbitrary
173
- // / `std::type_info` object.
174
- // / \param cache_key Specifies the cache key.
175
- // / \param make_cache Nullary function that returns an
176
- // / `std::unique_ptr<CacheType>`, where `CacheType` as a type that inherits
177
- // / from `Cache` or defines a `Cache& cache()` method. A `nullptr` may be
178
- // / returned to indicate an error creating the cache (any additional error
179
- // / information must be communicated via some separate out-of-band channel).
180
- template <typename CacheType, typename MakeCache>
181
- CachePtr<CacheType> GetCacheWithExplicitTypeInfo (
182
- CachePool* pool, const std::type_info& type_info,
183
- std::string_view cache_key, MakeCache&& make_cache) {
184
- auto cache = internal_cache::GetCacheInternal (
185
- internal_cache::Access::StaticCast<internal_cache::CachePoolImpl>(pool),
186
- type_info, cache_key, [&]() -> std::unique_ptr<internal::Cache> {
187
- std::unique_ptr<CacheType> cache = make_cache ();
188
- if (!cache) return nullptr ;
189
- void * user_ptr = cache.get ();
190
- auto base_ptr = std::unique_ptr<internal::Cache>(
191
- &internal_cache::GetCacheObject (cache.release ()));
192
- internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
193
- base_ptr.get ())
194
- ->user_ptr_ = user_ptr;
195
- return base_ptr;
196
- });
197
- if (!cache) return nullptr ;
198
- return CachePtr<CacheType>(
199
- static_cast <CacheType*>(
200
- internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
201
- cache.release ())
202
- ->user_ptr_ ),
203
- internal::adopt_object_ref);
204
- }
205
- template <typename CacheType, typename MakeCache>
206
- CachePtr<CacheType> GetCache (CachePool* pool, std::string_view cache_key,
207
- MakeCache&& make_cache) {
208
- return GetCacheWithExplicitTypeInfo<CacheType>(
209
- pool, typeid (CacheType), cache_key, std::forward<MakeCache>(make_cache));
210
- }
211
-
212
161
// / Pointer to a cache entry that prevents it from being evicted due to memory
213
162
// / pressure, but still permits it to be destroyed if its parent cache is
214
163
// / destroyed.
@@ -373,6 +322,57 @@ class Cache : private internal_cache::CacheImpl {
373
322
friend class internal_cache ::Access;
374
323
};
375
324
325
+ // / Returns a cache of type `CacheType` for the specified `cache_key`.
326
+ // /
327
+ // / If such a cache does not already exist, or `cache_key` is empty,
328
+ // / `make_cache()` is called to obtain a new such cache.
329
+ // /
330
+ // / \tparam CacheType Must be a class that inherits from `Cache`, or defines a
331
+ // / `Cache& cache()` method.
332
+ // / \param pool Cache pool, may be `nullptr` to indicate that caching is
333
+ // / disabled.
334
+ // / \param type_info Additional key used in looking up the cache. Has no effect
335
+ // / if `cache_key` is the empty string or `pool` is `nullptr`. Set to
336
+ // / `typeid(CacheType)` when calling `GetCache`, but can be any arbitrary
337
+ // / `std::type_info` object.
338
+ // / \param cache_key Specifies the cache key.
339
+ // / \param make_cache Nullary function that returns an
340
+ // / `std::unique_ptr<CacheType>`, where `CacheType` as a type that inherits
341
+ // / from `Cache` or defines a `Cache& cache()` method. A `nullptr` may be
342
+ // / returned to indicate an error creating the cache (any additional error
343
+ // / information must be communicated via some separate out-of-band channel).
344
+ template <typename CacheType, typename MakeCache>
345
+ CachePtr<CacheType> GetCacheWithExplicitTypeInfo (
346
+ CachePool* pool, const std::type_info& type_info,
347
+ std::string_view cache_key, MakeCache&& make_cache) {
348
+ auto cache = internal_cache::GetCacheInternal (
349
+ internal_cache::Access::StaticCast<internal_cache::CachePoolImpl>(pool),
350
+ type_info, cache_key, [&]() -> std::unique_ptr<internal::Cache> {
351
+ std::unique_ptr<CacheType> cache = make_cache ();
352
+ if (!cache) return nullptr ;
353
+ void * user_ptr = cache.get ();
354
+ auto base_ptr = std::unique_ptr<internal::Cache>(
355
+ &internal_cache::GetCacheObject (cache.release ()));
356
+ internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
357
+ base_ptr.get ())
358
+ ->user_ptr_ = user_ptr;
359
+ return base_ptr;
360
+ });
361
+ if (!cache) return nullptr ;
362
+ return CachePtr<CacheType>(
363
+ static_cast <CacheType*>(
364
+ internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
365
+ cache.release ())
366
+ ->user_ptr_ ),
367
+ internal::adopt_object_ref);
368
+ }
369
+ template <typename CacheType, typename MakeCache>
370
+ CachePtr<CacheType> GetCache (CachePool* pool, std::string_view cache_key,
371
+ MakeCache&& make_cache) {
372
+ return GetCacheWithExplicitTypeInfo<CacheType>(
373
+ pool, typeid (CacheType), cache_key, std::forward<MakeCache>(make_cache));
374
+ }
375
+
376
376
// / Returns a reference to the cache that contains `entry`. The reference
377
377
// / lifetime is tied to the lifetime of `entry`, but the lifetime of the cache
378
378
// / may be extended by creating a CachePtr.
0 commit comments