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 Class Reference

Manages the on-disk remote cache used by MRML storage. More...

#include <Libs/MRML/Core/vtkCacheManager.h>

Inheritance diagram for vtkCacheManager:
Collaboration diagram for vtkCacheManager:

Classes

struct  CacheEntry
 Describes a top-level item (file or folder) in the cache directory. More...
 

Public Types

enum  { NoCachedFile = 0 , OldCachedFile , CachedFile }
 Currently these are not used. More...
 
enum  {
  InsufficientFreeBufferEvent = 21000 , CacheLimitExceededEvent , CacheDeleteEvent , CacheDirtyEvent ,
  CacheClearEvent
}
 
typedef vtkObject Superclass
 

Public Member Functions

virtual bool CachedFileExists (const char *filename)
 
virtual bool CachedFileExists (const std::string &filename)
 
bool ClearCache ()
 Removes all files from the cachedir.
 
bool CreateSentinelFile () const
 Creates the sentinel file in the current cache directory.
 
bool CreateSentinelFileInDirectory (const std::string &directoryPath) const
 Creates the sentinel file in the specified directory.
 
void DeleteFromCache (const char *target)
 
void DeleteFromCache (const std::string &filename)
 
std::string EncodeURI (const char *uri)
 
std::string FindCachedFile (const char *target, const char *dirname)
 
std::vector< std::string > GetCachedFiles () const
 
std::vector< std::string > GetCachedFilesInDirectory (const std::string &directoryPath)
 
std::vector< CacheEntryGetCacheEntries () const
 
virtual const char * GetClassName ()
 
float GetCurrentCacheSize ()
 Current cache size in MB. Updated by UpdateCacheInformation().
 
virtual int GetEnableForceRedownload ()
 
const char * GetFileFromURIMap (const char *uri)
 
std::string GetFilenameFromURI (const char *uri)
 
std::string GetFilenameFromURI (const std::string &uri)
 
float GetFreeCacheSpaceRemaining ()
 Returns the amount of free space remaining in the cache directory, in MB. Updated by UpdateCacheInformation().
 
virtual int GetInsufficientFreeBufferNotificationFlag ()
 
const char * GetRemoteCacheDirectory ()
 Returns the name of the directory to use for local file caching.
 
virtual int GetRemoteCacheLimit ()
 Cache size limit in MB.
 
std::string GetSentinelFileName () const
 Sentinel file name used to identify cache directories where file deletion is allowed.
 
bool HasSentinelFile () const
 True if the sentinel file exists in the current cache directory.
 
bool HasSentinelFileInDirectory (const std::string &directoryPath) const
 True if the sentinel file exists in the specified directory.
 
virtual int IsA (const char *type)
 
bool IsDirectoryEmpty (const std::string &directoryPath) const
 Returns true if the specified directory is empty.
 
virtual bool IsLocalReference (const char *uri)
 Looks for a 'file://' in the URI and if present, returns true.
 
virtual bool IsRemoteReference (const char *uri)
 
virtual bool LocalFileExists (const char *uri)
 
void MapFileToURI (const char *uri, const char *fname)
 
void PrintSelf (ostream &os, vtkIndent indent) override
 
bool PruneCache ()
 
virtual void SetEnableForceRedownload (int)
 
virtual void SetInsufficientFreeBufferNotificationFlag (int)
 
void SetMRMLScene (vtkMRMLScene *scene)
 
virtual void SetRemoteCacheDirectory (const char *dir)
 
virtual void SetRemoteCacheDirectory (const std::string &dir)
 
virtual void SetRemoteCacheLimit (int)
 
void UpdateCacheInformation ()
 Called when a file is loaded or removed from the cache.
 

Static Public Member Functions

static int IsTypeOf (const char *type)
 
static vtkCacheManagerNew ()
 The Usual vtk class functions.
 
static vtkCacheManagerSafeDownCast (vtkObject *o)
 

Protected Member Functions

void operator= (const vtkCacheManager &)
 
 vtkCacheManager ()
 
 vtkCacheManager (const vtkCacheManager &)
 
 ~vtkCacheManager () override
 

Protected Attributes

vtkCallbackCommand * CallbackCommand
 Holder for callback.
 

Detailed Description

Manages the on-disk remote cache used by MRML storage.

The class manages a folder that stores temporary files, mostly used for local caching of remote data.

The cache folder needs to be cleaned when the maximum size is reached. To prevent accidental deletion of non-cache user data, the class uses a "sentinel file" mechanism. Presence of a sentinel file (.slicer-cache) in the folder marks it as owned by the cache manager, allowing the cache manager to delete files in it. Deletion is strictly limited to files within the cache directory (symlinks are resolved and file is only deleted if the canonicalized path is inside the cache root folder).

Definition at line 32 of file vtkCacheManager.h.

Member Typedef Documentation

◆ Superclass

typedef vtkObject vtkCacheManager::Superclass

Definition at line 37 of file vtkCacheManager.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Currently these are not used.

Enumerator
NoCachedFile 
OldCachedFile 
CachedFile 

Definition at line 172 of file vtkCacheManager.h.

◆ anonymous enum

anonymous enum
Enumerator
InsufficientFreeBufferEvent 
CacheLimitExceededEvent 
CacheDeleteEvent 
CacheDirtyEvent 
CacheClearEvent 

Definition at line 179 of file vtkCacheManager.h.

Constructor & Destructor Documentation

◆ vtkCacheManager() [1/2]

vtkCacheManager::vtkCacheManager ( )
protected

◆ ~vtkCacheManager()

vtkCacheManager::~vtkCacheManager ( )
overrideprotected

◆ vtkCacheManager() [2/2]

vtkCacheManager::vtkCacheManager ( const vtkCacheManager & )
protected

Member Function Documentation

◆ CachedFileExists() [1/2]

virtual bool vtkCacheManager::CachedFileExists ( const char * filename)
virtual

Checks to see if the The URI provided exists on disk. If not, it appends the Remote Cache Directory path and checks again, in case no path was provided. If neither exists, returns false. If one exists, returns true.

◆ CachedFileExists() [2/2]

virtual bool vtkCacheManager::CachedFileExists ( const std::string & filename)
virtual

◆ ClearCache()

bool vtkCacheManager::ClearCache ( )

Removes all files from the cachedir.

◆ CreateSentinelFile()

bool vtkCacheManager::CreateSentinelFile ( ) const

Creates the sentinel file in the current cache directory.

◆ CreateSentinelFileInDirectory()

bool vtkCacheManager::CreateSentinelFileInDirectory ( const std::string & directoryPath) const

Creates the sentinel file in the specified directory.

◆ DeleteFromCache() [1/2]

void vtkCacheManager::DeleteFromCache ( const char * target)

Remove a target directory or file from the cache folder. If the target is a directory, it will be removed recursively. Before deletion, any MRML nodes that hold the URI as a reference will be marked as "modified since read".

◆ DeleteFromCache() [2/2]

void vtkCacheManager::DeleteFromCache ( const std::string & filename)

◆ EncodeURI()

std::string vtkCacheManager::EncodeURI ( const char * uri)

◆ FindCachedFile()

std::string vtkCacheManager::FindCachedFile ( const char * target,
const char * dirname )

Takes a filename and a dirname (usually called with the RemoteCachedDirectory) and returns the full path of the filename if it exists under the dirname.

◆ GetCachedFiles()

std::vector< std::string > vtkCacheManager::GetCachedFiles ( ) const

Get list of cached files. Updated by UpdateCacheInformation(). Get files in the folder, ordered by modification time from newest to oldest. Does not include the sentinel file.

◆ GetCachedFilesInDirectory()

std::vector< std::string > vtkCacheManager::GetCachedFilesInDirectory ( const std::string & directoryPath)

Get files in the folder, ordered by modification time from newest to oldest. Does not include the sentinel file.

◆ GetCacheEntries()

std::vector< CacheEntry > vtkCacheManager::GetCacheEntries ( ) const

Returns one CacheEntry per top-level item in the cache directory. Updated by UpdateCacheInformation() Entries are sorted newest-first (descending ModifiedTime). Does not include the sentinel file. CacheEntry::ExceedsCacheSize is set for entries that PruneCache() would evict.

◆ GetClassName()

virtual const char * vtkCacheManager::GetClassName ( )
virtual

◆ GetCurrentCacheSize()

float vtkCacheManager::GetCurrentCacheSize ( )

Current cache size in MB. Updated by UpdateCacheInformation().

◆ GetEnableForceRedownload()

virtual int vtkCacheManager::GetEnableForceRedownload ( )
virtual

◆ GetFileFromURIMap()

const char * vtkCacheManager::GetFileFromURIMap ( const char * uri)

◆ GetFilenameFromURI() [1/2]

std::string vtkCacheManager::GetFilenameFromURI ( const char * uri)

Extracts the filename from the URI and prepends the Remote Cache Directory path to it. Returns the full path. NOTE: this method looks at a filename's extension and if appended version numbers have been added, it attempts to strip them out of the extension and add them to the filenamebase. So filename.nrrd_010 would become filename.nrrd. This will cause problems for any file type with an '_' in its extension.

◆ GetFilenameFromURI() [2/2]

std::string vtkCacheManager::GetFilenameFromURI ( const std::string & uri)

◆ GetFreeCacheSpaceRemaining()

float vtkCacheManager::GetFreeCacheSpaceRemaining ( )

Returns the amount of free space remaining in the cache directory, in MB. Updated by UpdateCacheInformation().

◆ GetInsufficientFreeBufferNotificationFlag()

virtual int vtkCacheManager::GetInsufficientFreeBufferNotificationFlag ( )
virtual

◆ GetRemoteCacheDirectory()

const char * vtkCacheManager::GetRemoteCacheDirectory ( )

Returns the name of the directory to use for local file caching.

◆ GetRemoteCacheLimit()

virtual int vtkCacheManager::GetRemoteCacheLimit ( )
virtual

Cache size limit in MB.

◆ GetSentinelFileName()

std::string vtkCacheManager::GetSentinelFileName ( ) const

Sentinel file name used to identify cache directories where file deletion is allowed.

◆ HasSentinelFile()

bool vtkCacheManager::HasSentinelFile ( ) const

True if the sentinel file exists in the current cache directory.

◆ HasSentinelFileInDirectory()

bool vtkCacheManager::HasSentinelFileInDirectory ( const std::string & directoryPath) const

True if the sentinel file exists in the specified directory.

◆ IsA()

virtual int vtkCacheManager::IsA ( const char * type)
virtual

◆ IsDirectoryEmpty()

bool vtkCacheManager::IsDirectoryEmpty ( const std::string & directoryPath) const

Returns true if the specified directory is empty.

◆ IsLocalReference()

virtual bool vtkCacheManager::IsLocalReference ( const char * uri)
virtual

Looks for a 'file://' in the URI and if present, returns true.

◆ IsRemoteReference()

virtual bool vtkCacheManager::IsRemoteReference ( const char * uri)
virtual

Checks to see if a URI appears to point to remote location and returns true if so. Looks for a '://' and if present, checks to see if the prefix is 'file'. If not 'file' but the thing:/// pattern exists, then returns true.

◆ IsTypeOf()

static int vtkCacheManager::IsTypeOf ( const char * type)
static

◆ LocalFileExists()

virtual bool vtkCacheManager::LocalFileExists ( const char * uri)
virtual

Checks to see if a URI is a file on disk and returns true if so. Strips off a file:/// prefix if present, and expects an absolute path.

◆ MapFileToURI()

void vtkCacheManager::MapFileToURI ( const char * uri,
const char * fname )

◆ New()

static vtkCacheManager * vtkCacheManager::New ( )
static

The Usual vtk class functions.

◆ operator=()

void vtkCacheManager::operator= ( const vtkCacheManager & )
protected

◆ PrintSelf()

void vtkCacheManager::PrintSelf ( ostream & os,
vtkIndent indent )
override

◆ PruneCache()

bool vtkCacheManager::PruneCache ( )

Delete oldest files until on-disk cache usage fits within RemoteCacheLimit. Returns true on success and false on failure.

◆ SafeDownCast()

static vtkCacheManager * vtkCacheManager::SafeDownCast ( vtkObject * o)
static

◆ SetEnableForceRedownload()

virtual void vtkCacheManager::SetEnableForceRedownload ( int )
virtual

◆ SetInsufficientFreeBufferNotificationFlag()

virtual void vtkCacheManager::SetInsufficientFreeBufferNotificationFlag ( int )
virtual

◆ SetMRMLScene()

void vtkCacheManager::SetMRMLScene ( vtkMRMLScene * scene)
inline

Definition at line 40 of file vtkCacheManager.h.

◆ SetRemoteCacheDirectory() [1/2]

virtual void vtkCacheManager::SetRemoteCacheDirectory ( const char * dir)
virtual

Sets the name of the directory to use for local file caching Does some checking to make sure this is a valid directory on the local system. Makes sure there's NO "/" at the end of the string, or kwsys/SystemTools will not see as a valid dir.

◆ SetRemoteCacheDirectory() [2/2]

virtual void vtkCacheManager::SetRemoteCacheDirectory ( const std::string & dir)
inlinevirtual

Definition at line 48 of file vtkCacheManager.h.

◆ SetRemoteCacheLimit()

virtual void vtkCacheManager::SetRemoteCacheLimit ( int )
virtual

◆ UpdateCacheInformation()

void vtkCacheManager::UpdateCacheInformation ( )

Called when a file is loaded or removed from the cache.

Member Data Documentation

◆ CallbackCommand

vtkCallbackCommand* vtkCacheManager::CallbackCommand
protected

Holder for callback.

Definition at line 234 of file vtkCacheManager.h.


The documentation for this class was generated from the following file: