/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include namespace facebook { namespace react { using ParagraphMeasurementCacheKey = std::tuple; using ParagraphMeasurementCacheValue = Size; class ParagraphMeasurementCache { public: ParagraphMeasurementCache() : cache_{256} {} bool exists(const ParagraphMeasurementCacheKey &key) const { std::lock_guard lock(mutex_); return cache_.exists(key); } ParagraphMeasurementCacheValue get( const ParagraphMeasurementCacheKey &key) const { std::lock_guard lock(mutex_); return cache_.get(key); } void set( const ParagraphMeasurementCacheKey &key, const ParagraphMeasurementCacheValue &value) const { std::lock_guard lock(mutex_); cache_.set(key, value); } private: mutable folly::EvictingCacheMap< ParagraphMeasurementCacheKey, ParagraphMeasurementCacheValue> cache_; mutable std::mutex mutex_; }; } // namespace react } // namespace facebook