Core::LocatorFileCache Class
class Core::LocatorFileCacheLocatorFileCache 类封装了实现文件过滤器缓存所需的所有职责。更多内容...
| Header: | #include <LocatorFileCache> |
公共函数
| LocatorFileCache() | |
| void | invalidate() |
| QtTaskTree::ExecutableItem | matcher() const |
| void | setFilePaths(const Utils::FilePaths &filePaths) |
| void | setFilePathsGenerator(const Core::LocatorFileCache::FilePathsGenerator &generator) |
| void | setGeneratorProvider(const Core::LocatorFileCache::GeneratorProvider &provider) |
静态公共成员
| Core::LocatorFileCache::FilePathsGenerator | filePathsGenerator(const Utils::FilePaths &filePaths) |
| Utils::FilePaths | processFilePaths(const QFuture<void> &future, const Utils::FilePaths &filePaths, bool hasPathSeparator, const QRegularExpression ®Exp, const Utils::Link &inputLink, Core::LocatorFileCache::MatchedEntries *entries) |
成员函数文档
LocatorFileCache::LocatorFileCache()
构建一个无效的缓存。
在调用invalidate()之后,或者在调用setFilePathsGenerator()时传入的函数为空的情况下,缓存将被视为处于无效状态。
可以通过setGeneratorProvider() 函数为缓存设置自动验证器。
另请参阅 invalidate 、setGeneratorProvider 、setFilePathsGenerator 以及setFilePaths 。
[static] Core::LocatorFileCache::FilePathsGenerator LocatorFileCache::filePathsGenerator(const Utils::FilePaths &filePaths)
将filePaths 列表转换为LocatorFileCacheGenerator。在实现GeneratorProvider时,若无法从非主线程调用文件路径的创建操作,此方法非常有用。
另请参阅 setFilePathsGenerator()。
void LocatorFileCache::invalidate()
清空缓存。
若要验证缓存,请使用 `setFilePathsGenerator()` 或 `setFilePaths()`。如果 `GeneratorProvider` 是通过 `setGeneratorProvider()` 设置的,则缓存可能会自动被验证。
注意:此 函数会永久失效缓存,清除所有缓存数据,并移除存储的生成器。存储的生成器提供程序将予以保留。
QtTaskTree::ExecutableItem LocatorFileCache::matcher() const
返回缓存的定位器匹配器任务。该任务成功完成后,会在必要时更新此LocatorFileCache 实例。
此方法应由 FilePaths 过滤器直接使用。FilePaths 过滤器应在内部保留一个 `LocatorFileCache ` 实例。请确保 `LocatorFileCache ` 实例的存活时间长于正在运行的匹配器,否则任务完成后缓存将不会被更新。
当返回的 LocatorMatcherTask 正在运行时,它会检查此缓存是否有效。如果缓存无效,它将使用 GeneratorProvider 更新缓存中的 FilePathsGenerator 并验证缓存。如果验证失败,则任务不会启动。 当缓存有效时,正在运行的任务将复用缓存数据来计算 LocatorMatcherTask 的结果。
任务运行成功后,该缓存将根据上次搜索结果进行更新。如果在此期间该缓存已启动新的搜索、被标记为无效甚至被删除,则任务运行成功后对缓存的更新将被忽略。
[static] Utils::FilePaths LocatorFileCache::processFilePaths(const QFuture<void> &future, const Utils::FilePaths &filePaths, bool hasPathSeparator, const QRegularExpression ®Exp, const Utils::Link &inputLink, Core::LocatorFileCache::MatchedEntries *entries)
该辅助函数在内部以及由 SpotlightLocatorFilter 使用。
需在非主线程中调用。取消操作由传入的future 控制。该函数会定期检查future 的取消状态,并在检测到取消时提前返回。创建按MatcherType分类的匹配LocatorFilterEntries列表。这些列表通过entries 参数返回。
返回所有匹配文件的列表。
该函数会检查filePaths 中的每个文件是否与传入的regExp 匹配。如果匹配,则使用hasPathSeparator 和inputLink 创建一个新条目,并将其添加到entries 参数和结果列表中。
void LocatorFileCache::setFilePaths(const Utils::FilePaths &filePaths)
将传入的filePaths 包装成一个简单的FilePathsGenerator,并将其设置为缓存的生成器。
注意:此 函数会暂时使缓存失效,清除所有缓存数据,并使用传入的filePaths 的新生成器将其恢复为有效状态。已存储的生成器提供程序将被保留。
另请参阅 setGeneratorProvider 。
void LocatorFileCache::setFilePathsGenerator(const Core::LocatorFileCache::FilePathsGenerator &generator)
设置文件路径生成器。
当关联的 LocatorMatherTask 在单独的线程中运行时,generator 用于返回完整的文件路径输入列表。 当计算完整的文件路径列表需要花费相当长的时间时,可以将此计算移至单独的线程中进行,前提是当在主线程中设置该函数时,所有依赖数据都能安全地传递给 `generator ` 函数。
当运行由 `matcher()` 返回的 `LocatorMatcherTask` 时,传递的 `generator ` 函数始终仅由非主线程调用。该函数会在缓存数据为空时被调用,或者当因新搜索而需要重新生成数据(且无法复用前次搜索的缓存)时被调用。
生成新的文件路径列表可能是一项耗时的任务。为了在任务被取消时能尽早完成该任务,可以使用 FilePathsGenerator 的future参数。FilePathsGenerator 返回用于文件过滤器处理的完整文件路径列表。
只要有可能推迟文件路径列表的创建,以便稍后基于其他可重入/线程安全的数据在非主线程中安全地完成该操作,就应使用此方法。 其他相关数据应通过lambda捕获传递。传递的generator 的本体应格外注意确保通过lambda捕获传递的其他数据是可重入的,且lambda本体是线程安全的。请参阅CppIncludesFilter实现中生成器的使用示例。
否则,当延迟创建文件路径列表不安全时,请使用setFilePaths() 并传入在主线程中预先准备好的列表。
注意:此 函数会使缓存失效,清除所有缓存数据;如果传入的生成器不为空,则会将缓存设置为有效状态。已存储的生成器提供程序将被保留。
另请参阅 filePathsGenerator()、setGeneratorProvider 和setFilePaths 。
void LocatorFileCache::setGeneratorProvider(const Core::LocatorFileCache::GeneratorProvider &provider)
设置文件路径生成器提供程序。
provider 用于通过重新创建 FilePathsGenerator 来自动验证无效缓存。当由matcher() 返回的 LocatorMatcherTask 启动时,若此时缓存无效,则会触发自动验证。在此情况下,将调用存储的provider 。
传入的provider 函数始终由主线程调用。如有需要,该函数会在启动用于收集定位器过滤器结果的异步任务之前被调用。
调用此函数时,缓存不会被失效。每当缓存发生失效时(例如调用invalidate()、setFilePathsGenerator() 或setFilePaths() 时),存储的 GeneratorProvider 都会被保留。若要清除存储的 GeneratorProvider,请使用空函数 {} 调用此方法。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.