11 #ifndef __GU_AgentFileCache__
12 #define __GU_AgentFileCache__
41 CachedFile(
T *
ptr =
nullptr, time_t mod_time = 0)
42 : myPtr(
ptr), myModTime(mod_time)
59 if (!ref->conditionalAddRef())
65 time_t getModTime()
const {
return myModTime; }
72 using CachedFileMap = UT_ConcurrentHashMap<UT_StringHolder, CachedFile>;
73 CachedFileMap myFiles;
97 typename CachedFileMap::const_accessor acc;
99 acc->second.getModTime() == mod_time &&
100 (item = acc->second.tryGetItem()))
106 typename CachedFileMap::accessor acc;
107 if (myFiles.insert(acc, key) || acc->second.getModTime() != mod_time
108 || !(item = acc->second.tryGetItem()))
111 auto new_item = load_new_item();
113 acc->second = CachedFile(new_item.get(), mod_time);
119 (
void) myFiles.erase(acc);
131 template <
typename T>
GT_API const UT_StringHolder filename
bool hasAccess(int mode=0) const
GU_API void GUgetAgentFilePaths(UT_StringArray &paths, const UT_StringHolder &condensed_path, const UT_StringHolder &expanded_path)
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRef(const UT_StringRef &ref)
Convert a UT_StringRef into a UT_StringHolder that is a shallow reference.
void removeCachedFile(const UT_StringRef &key)
Removes a cached file with the given key.
Wrapper around hboost::intrusive_ptr.
UT_IntrusivePtr< T > findCachedFileOrLoad(const UT_StringRef &filename, const UT_StringRef &key, F load_new_item)
time_t getModTime() const
Class for retrieving file information.