Blender V5.0
blender::memory_cache Namespace Reference

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< CachedValueget_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 Tget_loaded (const GenericKey &loader_key, Span< StringRefNull > file_paths, FunctionRef< std::unique_ptr< T >()> load_fn)
std::shared_ptr< CachedValueget_loaded_base (const GenericKey &loader_key, Span< StringRefNull > file_paths, FunctionRef< std::unique_ptr< CachedValue >()> load_fn)
static Cacheget_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_tget_file_modification_time (const StringRefNull path)
static FileStatMapget_file_stat_map ()
static void invalidate_outdated_caches_if_necessary (const Span< StringRefNull > file_paths)
Inline Functions
template<typename T>
std::shared_ptr< const Tget (const GenericKey &key, FunctionRef< std::unique_ptr< T >()> compute_fn)

Typedef Documentation

◆ CacheMap

using blender::memory_cache::CacheMap = ConcurrentMap<std::reference_wrapper<const GenericKey>, StoredValue>

Definition at line 33 of file memory_cache.cc.

Function Documentation

◆ clear()

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().

◆ get()

template<typename T>
std::shared_ptr< const T > blender::memory_cache::get ( const GenericKey & key,
FunctionRef< std::unique_ptr< T >()> compute_fn )
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().

◆ get_base()

◆ get_cache()

Cache & blender::memory_cache::get_cache ( )
static

Definition at line 56 of file memory_cache.cc.

Referenced by get_base(), remove_if(), set_approximate_size_limit(), and try_enforce_limit().

◆ get_file_modification_time()

std::optional< int64_t > blender::memory_cache::get_file_modification_time ( const StringRefNull path)
static

◆ get_file_stat_map()

FileStatMap & blender::memory_cache::get_file_stat_map ( )
static

Definition at line 83 of file memory_cache_file_load.cc.

Referenced by invalidate_outdated_caches_if_necessary().

◆ get_loaded()

template<typename T>
std::shared_ptr< const T > blender::memory_cache::get_loaded ( const GenericKey & loader_key,
Span< StringRefNull > file_paths,
FunctionRef< std::unique_ptr< T >()> load_fn )
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().

◆ get_loaded_base()

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 )

◆ invalidate_outdated_caches_if_necessary()

◆ remove_if() [1/2]

◆ remove_if() [2/2]

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().

◆ set_approximate_size_limit()

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().

◆ set_new_logical_time()

void blender::memory_cache::set_new_logical_time ( const StoredValue & stored_value,
const int64_t new_time )
static

Definition at line 64 of file memory_cache.cc.

References blender::memory_cache::StoredValue::last_use_time.

Referenced by get_base().

◆ try_enforce_limit()