Currently, the import nodes always reimport on each evaluation. This patch adds support for caching the loaded geometries. This is integrated with `BLI_memory_cache.hh` and thus also takes the cache size limit into account. If an imported file is modified on disk, the cache is invalidated. However, Geometry Nodes will not automatically reevaluate when a file changes, so the user would have to trigger the evaluation in some other way. This is an alternative solution to #124369. The main benefits are that the cache invalidation happens automatically and that the cache system is more general and does not have to know about e.g. the different file types. Caching speeds up node setups that heavily rely on import nodes significantly. Pull Request: https://projects.blender.org/blender/blender/pulls/138425
35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
/* SPDX-FileCopyrightText: 2025 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_memory_cache.hh"
|
|
#include "BLI_string_ref.hh"
|
|
|
|
namespace blender::memory_cache {
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
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);
|
|
|
|
template<typename T>
|
|
inline std::shared_ptr<const T> get_loaded(const GenericKey &loader_key,
|
|
Span<StringRefNull> file_paths,
|
|
FunctionRef<std::unique_ptr<T>()> load_fn)
|
|
{
|
|
return std::dynamic_pointer_cast<const T>(get_loaded_base(loader_key, file_paths, load_fn));
|
|
}
|
|
|
|
} // namespace blender::memory_cache
|