Make it possible to disable the file part of the flotsam asset cache
This matches the ability to disable the memory part This is controlled through the FileCacheEnabled parameter in FlotsamCache.ini Default is true, so existing installations are not affected. Improved fcache command feedback when various caches are disabled. Re-enabled test for flotsam cache with file caching disabled.bulletsim
parent
5dc785bbf2
commit
bebc51a6e0
|
@ -86,6 +86,8 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
private List<string> m_CurrentlyWriting = new List<string>();
|
||||
#endif
|
||||
|
||||
private bool m_FileCacheEnabled = true;
|
||||
|
||||
private ExpiringCache<string, AssetBase> m_MemoryCache;
|
||||
private bool m_MemoryCacheEnabled = false;
|
||||
|
||||
|
@ -146,6 +148,7 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
}
|
||||
else
|
||||
{
|
||||
m_FileCacheEnabled = assetConfig.GetBoolean("FileCacheEnabled", m_FileCacheEnabled);
|
||||
m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory);
|
||||
|
||||
m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled);
|
||||
|
@ -173,7 +176,7 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory);
|
||||
|
||||
if ((m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero))
|
||||
if (m_FileCacheEnabled && (m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero))
|
||||
{
|
||||
m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds);
|
||||
m_CacheCleanTimer.AutoReset = true;
|
||||
|
@ -312,6 +315,7 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
if (m_MemoryCacheEnabled)
|
||||
UpdateMemoryCache(asset.ID, asset);
|
||||
|
||||
if (m_FileCacheEnabled)
|
||||
UpdateFileCache(asset.ID, asset);
|
||||
}
|
||||
}
|
||||
|
@ -411,7 +415,7 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
|
||||
if (m_MemoryCacheEnabled)
|
||||
asset = GetFromMemoryCache(id);
|
||||
else
|
||||
else if (m_FileCacheEnabled)
|
||||
asset = GetFromFileCache(id);
|
||||
|
||||
if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0))
|
||||
|
@ -445,12 +449,15 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Expiring Asset {0}.", id);
|
||||
|
||||
try
|
||||
{
|
||||
if (m_FileCacheEnabled)
|
||||
{
|
||||
string filename = GetFileName(id);
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_MemoryCacheEnabled)
|
||||
m_MemoryCache.Remove(id);
|
||||
|
@ -464,12 +471,15 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
public void Clear()
|
||||
{
|
||||
if (m_LogLevel >= 2)
|
||||
m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache.");
|
||||
m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing caches.");
|
||||
|
||||
if (m_FileCacheEnabled)
|
||||
{
|
||||
foreach (string dir in Directory.GetDirectories(m_CacheDirectory))
|
||||
{
|
||||
Directory.Delete(dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_MemoryCacheEnabled)
|
||||
m_MemoryCache.Clear();
|
||||
|
@ -743,18 +753,28 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
switch (cmd)
|
||||
{
|
||||
case "status":
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache : {0} assets", m_MemoryCache.Count);
|
||||
if (m_MemoryCacheEnabled)
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Cache : {0} assets", m_MemoryCache.Count);
|
||||
else
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory cache disabled");
|
||||
|
||||
if (m_FileCacheEnabled)
|
||||
{
|
||||
int fileCount = GetFileCacheCount(m_CacheDirectory);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] File Cache : {0} assets", fileCount);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Cache : {0} assets", fileCount);
|
||||
|
||||
foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac"))
|
||||
{
|
||||
m_log.Info("[FLOTSAM ASSET CACHE] Deep Scans were performed on the following regions:");
|
||||
m_log.Info("[FLOTSAM ASSET CACHE]: Deep Scans were performed on the following regions:");
|
||||
|
||||
string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac","");
|
||||
DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss"));
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache disabled");
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -762,7 +782,7 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
case "clear":
|
||||
if (cmdparams.Length < 2)
|
||||
{
|
||||
m_log.Warn("[FLOTSAM ASSET CACHE] Usage is fcache clear [file] [memory]");
|
||||
m_log.Warn("[FLOTSAM ASSET CACHE]: Usage is fcache clear [file] [memory]");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -782,37 +802,49 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
}
|
||||
|
||||
if (clearMemory)
|
||||
{
|
||||
if (m_MemoryCacheEnabled)
|
||||
{
|
||||
m_MemoryCache.Clear();
|
||||
m_log.Info("[FLOTSAM ASSET CACHE] Memory cache cleared.");
|
||||
m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache cleared.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache not enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
if (clearFile)
|
||||
{
|
||||
if (m_FileCacheEnabled)
|
||||
{
|
||||
ClearFileCache();
|
||||
m_log.Info("[FLOTSAM ASSET CACHE] File cache cleared.");
|
||||
m_log.Info("[FLOTSAM ASSET CACHE]: File cache cleared.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Info("[FLOTSAM ASSET CACHE]: File cache not enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "assets":
|
||||
m_log.Info("[FLOTSAM ASSET CACHE] Caching all assets, in all scenes.");
|
||||
m_log.Info("[FLOTSAM ASSET CACHE]: Caching all assets, in all scenes.");
|
||||
|
||||
Util.FireAndForget(delegate {
|
||||
int assetsCached = CacheScenes();
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] Completed Scene Caching, {0} assets found.", assetsCached);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Completed Scene Caching, {0} assets found.", assetsCached);
|
||||
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "expire":
|
||||
|
||||
|
||||
if (cmdparams.Length < 3)
|
||||
{
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] Invalid parameters for Expire, please specify a valid date & time", cmd);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Invalid parameters for Expire, please specify a valid date & time", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -830,26 +862,28 @@ namespace Flotsam.RegionModules.AssetCache
|
|||
|
||||
if (!DateTime.TryParse(s_expirationDate, out expirationDate))
|
||||
{
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] {0} is not a valid date & time", cmd);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} is not a valid date & time", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_FileCacheEnabled)
|
||||
CleanExpiredFiles(m_CacheDirectory, expirationDate);
|
||||
else
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache not active, not clearing.");
|
||||
|
||||
break;
|
||||
default:
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] Unknown command {0}", cmd);
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Unknown command {0}", cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (cmdparams.Length == 1)
|
||||
{
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache status - Display cache status");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearmem - Remove all assets cached in memory");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache cachescenes - Attempt a deep cache of all assets in all scenes");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache <datetime> - Purge assets older then the specified date & time");
|
||||
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache status - Display cache status");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearmem - Remove all assets cached in memory");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearfile - Remove all assets cached on disk");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache cachescenes - Attempt a deep cache of all assets in all scenes");
|
||||
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache <datetime> - Purge assets older then the specified date & time");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace OpenSim.Region.CoreModules.Asset.Tests
|
|||
[TestFixture]
|
||||
public class FlotsamAssetCacheTests
|
||||
{
|
||||
// [Test]
|
||||
[Test]
|
||||
public void TestCacheAsset()
|
||||
{
|
||||
TestHelper.InMethod();
|
||||
|
@ -58,6 +58,7 @@ namespace OpenSim.Region.CoreModules.Asset.Tests
|
|||
config.AddConfig("Modules");
|
||||
config.Configs["Modules"].Set("AssetCaching", "FlotsamAssetCache");
|
||||
config.AddConfig("AssetCache");
|
||||
config.Configs["AssetCache"].Set("FileCacheEnabled", "false");
|
||||
config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true");
|
||||
|
||||
FlotsamAssetCache cache = new FlotsamAssetCache();
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
; 0 to disable
|
||||
HitRateDisplay = 100
|
||||
|
||||
; Set to false for disk cache only.
|
||||
; Set to false for no memory cache
|
||||
MemoryCacheEnabled = false
|
||||
|
||||
; Set to false for no file cache
|
||||
FileCacheEnabled = true
|
||||
|
||||
; How long {in hours} to keep assets cached in memory, .5 == 30 minutes
|
||||
; Optimization: for VPS or limited memory system installs set Timeout to .016 (1 minute)
|
||||
; increases performance without large memory impact
|
||||
|
|
Loading…
Reference in New Issue