1#ifndef __vtkCacheManager_h
2#define __vtkCacheManager_h
7class vtkCallbackCommand;
11#include <vtkWeakPointer.h>
18#ifndef vtkObjectPointer
19# define vtkObjectPointer(xx) (reinterpret_cast<vtkObject**>((xx)))
38 void PrintSelf(ostream& os, vtkIndent indent)
override;
55 vtkGetMacro(RemoteCacheLimit,
int);
56 vtkSetMacro(RemoteCacheLimit,
int);
163 vtkGetMacro(EnableForceRedownload,
int);
164 vtkSetMacro(EnableForceRedownload,
int);
166 vtkGetMacro(InsufficientFreeBufferNotificationFlag,
int);
167 vtkSetMacro(InsufficientFreeBufferNotificationFlag,
int);
191 struct vtkCacheManagerCachedFile
194 long long ModifiedTime;
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;
204 std::vector<CacheEntry> CacheEntries;
205 float CurrentCacheSize;
206 bool UpdatingCacheInformation;
208 bool CollectCachedFilesRecursively(
const std::string& directoryPath,
const std::string& rootDirectoryPath, std::vector<vtkCacheManagerCachedFile>& cachedFiles)
const;
213 void MarkNodesBeforeDeletingDataFromCache(
const char*);
215 void MarkNode(std::string);
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;
221 std::string GetSentinelFilePath(
const char* cacheDirectory)
const;
222 std::string GetSentinelFilePath(
const std::string& cacheDirectory)
const;
224 bool CanDeletePathInCache(
const char* cacheDirectory,
const char* pathToDelete, std::string& reason)
const;
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.
@ CacheLimitExceededEvent
@ InsufficientFreeBufferEvent
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