Slicer 5.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkCacheManager.h
Go to the documentation of this file.
1#ifndef __vtkCacheManager_h
2#define __vtkCacheManager_h
3
4// MRML includes
5#include "vtkMRML.h"
6#include "vtkMRMLScene.h"
7class vtkCallbackCommand;
8
9// VTK includes
10#include <vtkObject.h>
11#include <vtkWeakPointer.h>
12
13// STD includes
14#include <string>
15#include <vector>
16#include <map>
17
18#ifndef vtkObjectPointer
19# define vtkObjectPointer(xx) (reinterpret_cast<vtkObject**>((xx)))
20#endif
21
32class VTK_MRML_EXPORT vtkCacheManager : public vtkObject
33{
34public:
37 vtkTypeMacro(vtkCacheManager, vtkObject);
38 void PrintSelf(ostream& os, vtkIndent indent) override;
39
40 void SetMRMLScene(vtkMRMLScene* scene) { this->MRMLScene = scene; }
41
47 virtual void SetRemoteCacheDirectory(const char* dir);
48 virtual void SetRemoteCacheDirectory(const std::string& dir) { this->SetRemoteCacheDirectory(dir.c_str()); }
49
53
55 vtkGetMacro(RemoteCacheLimit, int);
56 vtkSetMacro(RemoteCacheLimit, int);
57
61
69 std::vector<std::string> GetCachedFiles() const;
70
73 {
74 std::string Path;
75 unsigned long long SizeBytes;
76 long long ModifiedTime;
80 };
81
87 std::vector<CacheEntry> GetCacheEntries() const;
88
91 bool PruneCache();
92
95 bool ClearCache();
96
100 void DeleteFromCache(const char* target);
101 void DeleteFromCache(const std::string& filename);
102
108 virtual bool IsRemoteReference(const char* uri);
109
112 virtual bool IsLocalReference(const char* uri);
113
118 virtual bool LocalFileExists(const char* uri);
119
124 std::string FindCachedFile(const char* target, const char* dirname);
125
131 virtual bool CachedFileExists(const char* filename);
132 virtual bool CachedFileExists(const std::string& filename);
133
142 std::string GetFilenameFromURI(const char* uri);
143 std::string GetFilenameFromURI(const std::string& uri);
144 std::string EncodeURI(const char* uri);
145
147 std::string GetSentinelFileName() const;
149 bool HasSentinelFile() const;
151 bool CreateSentinelFile() const;
152
154 bool IsDirectoryEmpty(const std::string& directoryPath) const;
156 bool HasSentinelFileInDirectory(const std::string& directoryPath) const;
158 bool CreateSentinelFileInDirectory(const std::string& directoryPath) const;
161 std::vector<std::string> GetCachedFilesInDirectory(const std::string& directoryPath);
162
163 vtkGetMacro(EnableForceRedownload, int);
164 vtkSetMacro(EnableForceRedownload, int);
165
166 vtkGetMacro(InsufficientFreeBufferNotificationFlag, int);
167 vtkSetMacro(InsufficientFreeBufferNotificationFlag, int);
168
169 void MapFileToURI(const char* uri, const char* fname);
170
172 enum
173 {
177 };
178
179 enum
180 {
186 };
187
188 const char* GetFileFromURIMap(const char* uri);
189
190private:
191 struct vtkCacheManagerCachedFile
192 {
193 std::string Path;
194 long long ModifiedTime;
195 };
196
197 vtkWeakPointer<vtkMRMLScene> MRMLScene;
198 std::string RemoteCacheDirectory;
199 std::map<std::string, std::string> UriMap;
200 int InsufficientFreeBufferNotificationFlag;
201 int RemoteCacheLimit;
202 int EnableForceRedownload;
203
204 std::vector<CacheEntry> CacheEntries;
205 float CurrentCacheSize;
206 bool UpdatingCacheInformation;
207
208 bool CollectCachedFilesRecursively(const std::string& directoryPath, const std::string& rootDirectoryPath, std::vector<vtkCacheManagerCachedFile>& cachedFiles) const;
209
213 void MarkNodesBeforeDeletingDataFromCache(const char*);
214
215 void MarkNode(std::string);
216
217 std::string CanonicalizePath(const char* path) const;
218 std::string JoinPath(const std::string& directoryPath, const std::string& fileName) const;
219 bool PathIsWithinDirectory(const std::string& directoryPath, const std::string& path) const;
220
221 std::string GetSentinelFilePath(const char* cacheDirectory) const;
222 std::string GetSentinelFilePath(const std::string& cacheDirectory) const;
223
224 bool CanDeletePathInCache(const char* cacheDirectory, const char* pathToDelete, std::string& reason) const;
225
226protected:
231
234 vtkCallbackCommand* CallbackCommand;
235};
236
237#endif
void UpdateCacheInformation()
Called when a file is loaded or removed from the cache.
virtual void SetRemoteCacheDirectory(const std::string &dir)
~vtkCacheManager() override
vtkCallbackCommand * CallbackCommand
Holder for callback.
bool IsDirectoryEmpty(const std::string &directoryPath) const
Returns true if the specified directory is empty.
bool ClearCache()
Removes all files from the cachedir.
std::string EncodeURI(const char *uri)
virtual bool IsLocalReference(const char *uri)
Looks for a 'file://' in the URI and if present, returns true.
std::string FindCachedFile(const char *target, const char *dirname)
std::string GetFilenameFromURI(const std::string &uri)
float GetFreeCacheSpaceRemaining()
Returns the amount of free space remaining in the cache directory, in MB. Updated by UpdateCacheInfor...
std::string GetFilenameFromURI(const char *uri)
void DeleteFromCache(const char *target)
void operator=(const vtkCacheManager &)
bool HasSentinelFileInDirectory(const std::string &directoryPath) const
True if the sentinel file exists in the specified directory.
const char * GetFileFromURIMap(const char *uri)
void MapFileToURI(const char *uri, const char *fname)
virtual bool LocalFileExists(const char *uri)
const char * GetRemoteCacheDirectory()
Returns the name of the directory to use for local file caching.
virtual void SetRemoteCacheDirectory(const char *dir)
std::vector< std::string > GetCachedFiles() const
static vtkCacheManager * New()
The Usual vtk class functions.
std::vector< std::string > GetCachedFilesInDirectory(const std::string &directoryPath)
virtual bool CachedFileExists(const char *filename)
void DeleteFromCache(const std::string &filename)
std::string GetSentinelFileName() const
Sentinel file name used to identify cache directories where file deletion is allowed.
bool CreateSentinelFile() const
Creates the sentinel file in the current cache directory.
virtual bool CachedFileExists(const std::string &filename)
vtkCacheManager(const vtkCacheManager &)
void PrintSelf(ostream &os, vtkIndent indent) override
virtual bool IsRemoteReference(const char *uri)
bool CreateSentinelFileInDirectory(const std::string &directoryPath) const
Creates the sentinel file in the specified directory.
bool HasSentinelFile() const
True if the sentinel file exists in the current cache directory.
float GetCurrentCacheSize()
Current cache size in MB. Updated by UpdateCacheInformation().
void SetMRMLScene(vtkMRMLScene *scene)
std::vector< CacheEntry > GetCacheEntries() const
A set of MRML Nodes that supports serialization and undo/redo.
Describes a top-level item (file or folder) in the cache directory.
int FileCount
number of files contained in the directory (0 for file entries)
bool ExceedsCacheSize
true if PruneCache() would remove this entry to bring the cache within its size limit
unsigned long long SizeBytes