|
Blender V5.0
|
Namespaces | |
| namespace | tests |
Classes | |
| class | CachedValue |
| struct | StoredValue |
| struct | Cache |
| class | LoadFileKey |
| struct | FileStatMap |
Typedefs | |
| using | CacheMap = ConcurrentMap<std::reference_wrapper<const GenericKey>, StoredValue> |
Functions | |
| std::shared_ptr< CachedValue > | get_base (const GenericKey &key, FunctionRef< std::unique_ptr< CachedValue >()> compute_fn) |
| void | set_approximate_size_limit (int64_t limit_in_bytes) |
| void | clear () |
| void | remove_if (FunctionRef< bool(const GenericKey &)> predicate) |
| template<typename T> | |
| std::shared_ptr< const T > | get_loaded (const GenericKey &loader_key, Span< StringRefNull > file_paths, FunctionRef< std::unique_ptr< T >()> load_fn) |
| std::shared_ptr< CachedValue > | get_loaded_base (const GenericKey &loader_key, Span< StringRefNull > file_paths, FunctionRef< std::unique_ptr< CachedValue >()> load_fn) |
| static Cache & | get_cache () |
| static void | try_enforce_limit () |
| static void | set_new_logical_time (const StoredValue &stored_value, const int64_t new_time) |
| void | remove_if (const FunctionRef< bool(const GenericKey &)> predicate) |
| static std::optional< int64_t > | get_file_modification_time (const StringRefNull path) |
| static FileStatMap & | get_file_stat_map () |
| static void | invalidate_outdated_caches_if_necessary (const Span< StringRefNull > file_paths) |
Inline Functions | |
| template<typename T> | |
| std::shared_ptr< const T > | get (const GenericKey &key, FunctionRef< std::unique_ptr< T >()> compute_fn) |
| using blender::memory_cache::CacheMap = ConcurrentMap<std::reference_wrapper<const GenericKey>, StoredValue> |
Definition at line 33 of file memory_cache.cc.
| void blender::memory_cache::clear | ( | ) |
Remove all elements from the cache. Note that this does not guarantee that no elements are in the cache after the function returned. This is because another thread may have added a new element right after the clearing.
Definition at line 139 of file memory_cache.cc.
References remove_if().
Referenced by blender::memory_cache::tests::TEST(), blender::memory_cache::tests::TEST(), and WM_exit_ex().
|
inline |
Returns the value that corresponds to the given key. If it's not cached yet, #compute_fn is called and its result is cached for the next time.
If the cache is full, older values may be freed.
Definition at line 72 of file BLI_memory_cache.hh.
References get_base().
Referenced by blender::memory_cache::tests::TEST(), and blender::memory_cache::tests::TEST().
| std::shared_ptr< CachedValue > blender::memory_cache::get_base | ( | const GenericKey & | key, |
| FunctionRef< std::unique_ptr< CachedValue >()> | compute_fn ) |
A non-templated version of the main entry point above.
Definition at line 74 of file memory_cache.cc.
References blender::ConcurrentMap< Key, Value, Hash, IsEqual >::add(), BLI_assert, get_cache(), blender::memory_cache::Cache::global_mutex, blender::memory_cache::Cache::keys, lock, blender::memory_cache::Cache::logical_time, blender::ConcurrentMap< Key, Value, Hash, IsEqual >::lookup(), blender::memory_cache::Cache::map, blender::memory_cache::Cache::memory, result, set_new_logical_time(), blender::memory_cache::Cache::size_in_bytes, blender::GenericKey::to_storable(), blender::memory_counter::MemoryCount::total_bytes, and try_enforce_limit().
Referenced by get(), and get_loaded_base().
|
static |
Definition at line 56 of file memory_cache.cc.
Referenced by get_base(), remove_if(), set_approximate_size_limit(), and try_enforce_limit().
|
static |
Definition at line 69 of file memory_cache_file_load.cc.
References BLI_stat(), and blender::StringRefNull::c_str().
Referenced by invalidate_outdated_caches_if_necessary().
|
static |
Definition at line 83 of file memory_cache_file_load.cc.
Referenced by invalidate_outdated_caches_if_necessary().
|
inline |
Call the given loader function if its result has not been cached yet. The cache key is a combination of loader_key and file_paths. load_fn is responsible for still producing a valid cache value even if a file is not found.
Definition at line 27 of file BLI_memory_cache_file_load.hh.
References get_loaded_base().
Referenced by blender::nodes::node_geo_import_csv::node_geo_exec(), blender::nodes::node_geo_import_obj::node_geo_exec(), blender::nodes::node_geo_import_stl::node_geo_exec(), blender::nodes::node_geo_import_text::node_geo_exec(), and blender::nodes::nodes_geo_import_ply::node_geo_exec().
| std::shared_ptr< CachedValue > blender::memory_cache::get_loaded_base | ( | const GenericKey & | loader_key, |
| Span< StringRefNull > | file_paths, | ||
| FunctionRef< std::unique_ptr< CachedValue >()> | load_fn ) |
Definition at line 134 of file memory_cache_file_load.cc.
References get_base(), invalidate_outdated_caches_if_necessary(), and blender::GenericKey::to_storable().
Referenced by get_loaded().
|
static |
Definition at line 89 of file memory_cache_file_load.cc.
References blender::VectorSet< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::Span< T >::begin(), blender::Span< T >::end(), get_file_modification_time(), get_file_stat_map(), i, blender::Span< T >::index_range(), blender::VectorSet< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::is_empty(), blender::threading::isolate_task(), lock, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_or_add_as(), blender::memory_cache::FileStatMap::map, blender::memory_cache::FileStatMap::mutex, remove_if(), and blender::Span< T >::size().
Referenced by get_loaded_base().
| void blender::memory_cache::remove_if | ( | const FunctionRef< bool(const GenericKey &)> | predicate | ) |
Definition at line 144 of file memory_cache.cc.
References BLI_assert, BLI_assert_unreachable, get_cache(), blender::memory_cache::Cache::global_mutex, i, blender::memory_cache::Cache::keys, lock, blender::ConcurrentMap< Key, Value, Hash, IsEqual >::lookup(), blender::memory_cache::Cache::map, blender::memory_cache::Cache::memory, blender::ConcurrentMap< Key, Value, Hash, IsEqual >::remove(), blender::memory_counter::MemoryCount::reset(), blender::memory_cache::Cache::size_in_bytes, blender::memory_counter::MemoryCount::total_bytes, and UNUSED_VARS_NDEBUG.
| void blender::memory_cache::remove_if | ( | FunctionRef< bool(const GenericKey &)> | predicate | ) |
Remove elements from the cache for which the predicate returns true. Note that this does not guarantee that there are no elements for which the predicate is true after the function returned. This is because another thread may have added a new element right after the removal.
Referenced by clear(), invalidate_outdated_caches_if_necessary(), and blender::memory_cache::tests::TEST().
| void blender::memory_cache::set_approximate_size_limit | ( | int64_t | limit_in_bytes | ) |
Set how much memory the cache is allowed to use. This is only an approximation because counting the memory is not 100% accurate, and for some types the memory usage may even change over time.
Definition at line 132 of file memory_cache.cc.
References blender::memory_cache::Cache::approximate_limit, get_cache(), and try_enforce_limit().
Referenced by wm_init_userdef().
|
static |
Definition at line 64 of file memory_cache.cc.
References blender::memory_cache::StoredValue::last_use_time.
Referenced by get_base().
|
static |
Definition at line 184 of file memory_cache.cc.
References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::memory_cache::Cache::approximate_limit, blender::Vector< T, InlineBufferCapacity, Allocator >::begin(), blender::IndexRange::drop_front(), blender::Vector< T, InlineBufferCapacity, Allocator >::end(), get_cache(), blender::memory_cache::Cache::global_mutex, i, blender::Vector< T, InlineBufferCapacity, Allocator >::index_range(), blender::memory_cache::Cache::keys, lock, blender::ConcurrentMap< Key, Value, Hash, IsEqual >::lookup(), blender::memory_cache::Cache::map, blender::memory_cache::Cache::memory, blender::ConcurrentMap< Key, Value, Hash, IsEqual >::remove(), blender::memory_counter::MemoryCount::reset(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), blender::memory_cache::Cache::size_in_bytes, blender::IndexRange::take_front(), and blender::memory_counter::MemoryCount::total_bytes.
Referenced by get_base(), and set_approximate_size_limit().