35const std::string
ClearCache::summary()
const {
return "Clears out selected cached information held by Mantidplot."; }
41 declareProperty(
"AlgorithmCache",
false,
"Clears the memory cache of the last used algorithm parameters.");
42 declareProperty(
"InstrumentCache",
false,
"Clears the memory cache of the loaded instrument definitions.");
44 "Clears the file cache of the downloaded instrument "
45 "definitions. This can be repopulated using "
46 "DownloadInstrument.");
47 declareProperty(
"GeometryFileCache",
false,
"Clears the file cache of the triangulated detector geometries.");
48 declareProperty(
"WorkspaceCache",
false,
"Clears the memory cache of any workspaces.");
49 declareProperty(
"UsageServiceCache",
false,
"Clears the memory cache of usage data.");
50 declareProperty(
"FilesRemoved", 0,
"The number of files removed. Memory clearance do not add to this.",
60 bool clearInstService =
getProperty(
"InstrumentCache");
61 bool clearInstFileCache =
getProperty(
"DownloadedInstrumentFileCache");
62 bool clearGeometryFileCache =
getProperty(
"GeometryFileCache");
63 bool clearUsageService =
getProperty(
"UsageServiceCache");
64 bool clearAnalysisService =
getProperty(
"WorkspaceCache");
66 bool isAnythingSelected = clearAlgCache || clearInstService || clearInstFileCache || clearGeometryFileCache ||
67 clearUsageService || clearAnalysisService;
68 if (!isAnythingSelected) {
74 auto instrumentDirs = Mantid::Kernel::ConfigService::Instance().getInstrumentDirectories();
75 std::filesystem::path localPath(instrumentDirs[0]);
78 g_log.
debug(
"Emptying the Algorithm cache (AlgorithmCache).");
79 AlgorithmManager::Instance().clear();
81 if (clearAnalysisService) {
82 g_log.
debug(
"Emptying the Analysis data service (WorkspaceCache).");
83 AnalysisDataService::Instance().clear();
85 if (clearInstService) {
86 g_log.
debug(
"Emptying the Instrument data service (InstrumentCache).");
87 InstrumentDataService::Instance().clear();
89 if (clearInstFileCache) {
90 g_log.
debug(
"Removing files from the Downloaded Instrument file cache "
91 "(DownloadedInstrumentFileCache).");
92 int filecount =
deleteFiles(localPath.string(),
"*.xml");
93 filecount +=
deleteFiles(localPath.string(),
"github.json");
95 filesRemoved += filecount;
97 if (clearGeometryFileCache) {
98 g_log.
debug(
"Removing files from the triangulated detector geometry file "
99 "cache (GeometryFileCache).");
100 std::filesystem::path GeomPath = localPath /
"geometryCache";
101 int filecount =
deleteFiles(GeomPath.string(),
"*.vtp");
103 filesRemoved += filecount;
105 if (clearUsageService) {
106 g_log.
debug(
"Emptying the Usage data service (UsageServiceCache).");
107 UsageService::Instance().clear();
118 int filesDeleted = 0;
120 std::filesystem::path pathPattern = std::filesystem::path(path) / pattern;
121 std::set<std::string> files;
124 for (
const auto &filepath : files) {
127 std::filesystem::remove(filepath);
129 }
catch (std::filesystem::filesystem_error &ex) {
130 g_log.
warning(
"Cannot delete file " + filepath +
": " + ex.what());
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
ClearCache : TODO: DESCRIPTION.
int version() const override final
Algorithm's version for identification.
void exec() override final
Execute the algorithm.
const std::string summary() const override final
Algorithm's summary for use in the GUI and help.
const std::string category() const override final
Algorithm's category for identification.
void init() override final
Initialize the algorithm's properties.
int deleteFiles(const std::string &path, const std::string &pattern) const
Deletes files on the path that match the pattern provided.
static void glob(const std::string &pathPattern, std::set< std::string > &files, int options=0)
Creates a set of files that match the given pathPattern.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
@ Output
An output workspace.