36const std::string
ClearCache::summary()
const {
return "Clears out selected cached information held by Mantidplot."; }
42 declareProperty(
"AlgorithmCache",
false,
"Clears the memory cache of the last used algorithm parameters.");
43 declareProperty(
"InstrumentCache",
false,
"Clears the memory cache of the loaded instrument definitions.");
45 "Clears the file cache of the downloaded instrument "
46 "definitions. This can be repopulated using "
47 "DownloadInstrument.");
48 declareProperty(
"GeometryFileCache",
false,
"Clears the file cache of the triangulated detector geometries.");
49 declareProperty(
"WorkspaceCache",
false,
"Clears the memory cache of any workspaces.");
50 declareProperty(
"UsageServiceCache",
false,
"Clears the memory cache of usage data.");
51 declareProperty(
"FilesRemoved", 0,
"The number of files removed. Memory clearance do not add to this.",
61 bool clearInstService =
getProperty(
"InstrumentCache");
62 bool clearInstFileCache =
getProperty(
"DownloadedInstrumentFileCache");
63 bool clearGeometryFileCache =
getProperty(
"GeometryFileCache");
64 bool clearUsageService =
getProperty(
"UsageServiceCache");
65 bool clearAnalysisService =
getProperty(
"WorkspaceCache");
67 bool isAnythingSelected = clearAlgCache || clearInstService || clearInstFileCache || clearGeometryFileCache ||
68 clearUsageService || clearAnalysisService;
69 if (!isAnythingSelected) {
76 Poco::Path localPath(instrumentDirs[0]);
77 localPath.makeDirectory();
80 g_log.
debug(
"Emptying the Algorithm cache (AlgorithmCache).");
83 if (clearAnalysisService) {
84 g_log.
debug(
"Emptying the Analysis data service (WorkspaceCache).");
87 if (clearInstService) {
88 g_log.
debug(
"Emptying the Instrument data service (InstrumentCache).");
91 if (clearInstFileCache) {
92 g_log.
debug(
"Removing files from the Downloaded Instrument file cache "
93 "(DownloadedInstrumentFileCache).");
94 int filecount =
deleteFiles(localPath.toString(),
"*.xml");
95 filecount +=
deleteFiles(localPath.toString(),
"github.json");
97 filesRemoved += filecount;
99 if (clearGeometryFileCache) {
100 g_log.
debug(
"Removing files from the triangulated detector geometry file "
101 "cache (GeometryFileCache).");
102 Poco::Path GeomPath(localPath);
103 GeomPath.append(
"geometryCache").makeDirectory();
104 int filecount =
deleteFiles(GeomPath.toString(),
"*.vtp");
106 filesRemoved += filecount;
108 if (clearUsageService) {
109 g_log.
debug(
"Emptying the Usage data service (UsageServiceCache).");
121 int filesDeleted = 0;
123 Poco::Path pathPattern(path);
124 pathPattern.makeDirectory();
125 pathPattern.append(pattern);
126 std::set<std::string> files;
127 Poco::Glob::glob(pathPattern, files, Poco::Glob::GLOB_CASELESS);
129 for (
const auto &filepath : files) {
130 Poco::File file(filepath);
135 }
catch (Poco::FileException &ex) {
136 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.
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.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ Output
An output workspace.