summaryrefslogtreecommitdiff
path: root/indra/llfilesystem/lldiskcache.h
diff options
context:
space:
mode:
authorCallum Prentice <callum@gmail.com>2020-10-07 16:43:01 -0700
committerCallum Prentice <callum@gmail.com>2020-10-07 16:43:01 -0700
commit1a9942a51c2b5db51adb75356f342665743d1f16 (patch)
tree1bdd6a2d5e860f09410599fa996092d962ddc31e /indra/llfilesystem/lldiskcache.h
parent5fdc4a1fb4a1788b20ca7a2e7764fd1391c35785 (diff)
Improve, rationalize and expand comments
Diffstat (limited to 'indra/llfilesystem/lldiskcache.h')
-rw-r--r--indra/llfilesystem/lldiskcache.h65
1 files changed, 62 insertions, 3 deletions
diff --git a/indra/llfilesystem/lldiskcache.h b/indra/llfilesystem/lldiskcache.h
index 34a4fda756..f718b7a328 100644
--- a/indra/llfilesystem/lldiskcache.h
+++ b/indra/llfilesystem/lldiskcache.h
@@ -1,6 +1,41 @@
/**
* @file lldiskcache.h
- * @brief The disk cache implementation.
+ * @brief The disk cache implementation declarations.
+ *
+ * @Description:
+ * This code implements a disk cache using the following ideas:
+ * 1/ The metadata for a file can be encapsulated in the filename.
+ The filenames will be composed of the following fields:
+ Prefix: Used to identify the file as a part of the cache.
+ An additional reason for using a prefix is that it
+ might be possible, either accidentally or maliciously
+ to end up with the cache dir set to a non-cache
+ location such as your OS system dir or a work folder.
+ Purging files from that would obviously be a disaster
+ so this is an extra step to help avoid that scenario.
+ ID: Typically the asset ID (UUID) of the asset being
+ saved but can be anything valid for a filename
+ Extra Info: A field for use in the future that can be used
+ to store extra identifiers - e.g. the discard
+ level of a JPEG2000 file
+ Asset Type: A text string created from the LLAssetType enum
+ that identifies the type of asset being stored.
+ .asset A file extension of .asset is used to help
+ identify this as a Viewer asset file
+ * 2/ The time of last access for a file can be updated instantly
+ * for file reads and automatically as part of the file writes.
+ * 3/ The purge algorithm collects a list of all files in the
+ * directory, sorts them by date of last access (write) and then
+ * deletes any files based on age until the total size of all
+ * the files is less than the maximum size specified.
+ * 4/ An LLSingleton idiom is used since there will only ever be
+ * a single cache and we want to access it from numerous places.
+ * 5/ Performance on my modest system seems very acceptable. For
+ * example, in testing, I was able to purge a directory of
+ * 10,000 files, deleting about half of them in ~ 1700ms. For
+ * the same sized directory of files, writing the last updated
+ * time to each took less than 600ms indicating that this
+ * important part of the mechanism has almost no overhead.
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -33,10 +68,32 @@ class LLDiskCache :
public LLParamSingleton<LLDiskCache>
{
public:
+ /**
+ * Since this is using the LLSingleton pattern but we
+ * want to allow the constructor to be called first
+ * with various parameters, we also invoke the
+ * LLParamSingleton idiom and use it to initialize
+ * the class via a call in LLAppViewer.
+ */
LLSINGLETON(LLDiskCache,
+ /**
+ * The full name of the cache folder - typically a
+ * a child of the main Viewer cache directory. Defined
+ * by the setting at 'DiskCacheDirName'
+ */
const std::string cache_dir,
+ /**
+ * The maximum size of the cache in bytes - Defined by
+ * the setting at 'DiskCacheMaxSizeMB' (* 1024 * 1024)
+ */
const int max_size_bytes,
+ /**
+ * A flag that enables extra cache debugging so that
+ * if there are bugs, we can ask uses to enable this
+ * setting and send us their logs
+ */
const bool enable_cache_debug_info);
+
virtual ~LLDiskCache() = default;
public:
@@ -54,7 +111,7 @@ class LLDiskCache :
/**
* Update the "last write time" of a file to "now". This must be called whenever a
* file in the cache is read (not written) so that the last time the file was
- * accessed which is used in the mechanism for purging the cache, is up to date.
+ * accessed is up to date (This is used in the mechanism for purging the cache)
*/
void updateFileAccessTime(const std::string file_path);
@@ -65,7 +122,9 @@ class LLDiskCache :
void purge();
/**
- * Clear the cache by removing the files in the cache directory individually
+ * Clear the cache by removing all the files in the specified cache
+ * directory individually. Only the files that contain a prefix defined
+ * by mCacheFilenamePrefix will be removed.
*/
void clearCache(const std::string cache_dir);