aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs110
1 files changed, 72 insertions, 38 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index a72cf83..2b3f7f5 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -86,6 +86,8 @@ namespace Flotsam.RegionModules.AssetCache
86 private List<string> m_CurrentlyWriting = new List<string>(); 86 private List<string> m_CurrentlyWriting = new List<string>();
87#endif 87#endif
88 88
89 private bool m_FileCacheEnabled = true;
90
89 private ExpiringCache<string, AssetBase> m_MemoryCache; 91 private ExpiringCache<string, AssetBase> m_MemoryCache;
90 private bool m_MemoryCacheEnabled = false; 92 private bool m_MemoryCacheEnabled = false;
91 93
@@ -146,6 +148,7 @@ namespace Flotsam.RegionModules.AssetCache
146 } 148 }
147 else 149 else
148 { 150 {
151 m_FileCacheEnabled = assetConfig.GetBoolean("FileCacheEnabled", m_FileCacheEnabled);
149 m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); 152 m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory);
150 153
151 m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled); 154 m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled);
@@ -173,7 +176,7 @@ namespace Flotsam.RegionModules.AssetCache
173 176
174 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory); 177 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory);
175 178
176 if ((m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero)) 179 if (m_FileCacheEnabled && (m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero))
177 { 180 {
178 m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds); 181 m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds);
179 m_CacheCleanTimer.AutoReset = true; 182 m_CacheCleanTimer.AutoReset = true;
@@ -312,7 +315,8 @@ namespace Flotsam.RegionModules.AssetCache
312 if (m_MemoryCacheEnabled) 315 if (m_MemoryCacheEnabled)
313 UpdateMemoryCache(asset.ID, asset); 316 UpdateMemoryCache(asset.ID, asset);
314 317
315 UpdateFileCache(asset.ID, asset); 318 if (m_FileCacheEnabled)
319 UpdateFileCache(asset.ID, asset);
316 } 320 }
317 } 321 }
318 322
@@ -411,7 +415,7 @@ namespace Flotsam.RegionModules.AssetCache
411 415
412 if (m_MemoryCacheEnabled) 416 if (m_MemoryCacheEnabled)
413 asset = GetFromMemoryCache(id); 417 asset = GetFromMemoryCache(id);
414 else 418 else if (m_FileCacheEnabled)
415 asset = GetFromFileCache(id); 419 asset = GetFromFileCache(id);
416 420
417 if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0)) 421 if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0))
@@ -446,10 +450,13 @@ namespace Flotsam.RegionModules.AssetCache
446 450
447 try 451 try
448 { 452 {
449 string filename = GetFileName(id); 453 if (m_FileCacheEnabled)
450 if (File.Exists(filename))
451 { 454 {
452 File.Delete(filename); 455 string filename = GetFileName(id);
456 if (File.Exists(filename))
457 {
458 File.Delete(filename);
459 }
453 } 460 }
454 461
455 if (m_MemoryCacheEnabled) 462 if (m_MemoryCacheEnabled)
@@ -464,11 +471,14 @@ namespace Flotsam.RegionModules.AssetCache
464 public void Clear() 471 public void Clear()
465 { 472 {
466 if (m_LogLevel >= 2) 473 if (m_LogLevel >= 2)
467 m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache."); 474 m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing caches.");
468 475
469 foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) 476 if (m_FileCacheEnabled)
470 { 477 {
471 Directory.Delete(dir); 478 foreach (string dir in Directory.GetDirectories(m_CacheDirectory))
479 {
480 Directory.Delete(dir);
481 }
472 } 482 }
473 483
474 if (m_MemoryCacheEnabled) 484 if (m_MemoryCacheEnabled)
@@ -743,18 +753,28 @@ namespace Flotsam.RegionModules.AssetCache
743 switch (cmd) 753 switch (cmd)
744 { 754 {
745 case "status": 755 case "status":
746 m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache : {0} assets", m_MemoryCache.Count); 756 if (m_MemoryCacheEnabled)
747 757 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Cache : {0} assets", m_MemoryCache.Count);
748 int fileCount = GetFileCacheCount(m_CacheDirectory); 758 else
749 m_log.InfoFormat("[FLOTSAM ASSET CACHE] File Cache : {0} assets", fileCount); 759 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory cache disabled");
750 760
751 foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac")) 761 if (m_FileCacheEnabled)
752 { 762 {
753 m_log.Info("[FLOTSAM ASSET CACHE] Deep Scans were performed on the following regions:"); 763 int fileCount = GetFileCacheCount(m_CacheDirectory);
754 764 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Cache : {0} assets", fileCount);
755 string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac",""); 765
756 DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s); 766 foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac"))
757 m_log.InfoFormat("[FLOTSAM ASSET CACHE] Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss")); 767 {
768 m_log.Info("[FLOTSAM ASSET CACHE]: Deep Scans were performed on the following regions:");
769
770 string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac","");
771 DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s);
772 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss"));
773 }
774 }
775 else
776 {
777 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache disabled");
758 } 778 }
759 779
760 break; 780 break;
@@ -762,7 +782,7 @@ namespace Flotsam.RegionModules.AssetCache
762 case "clear": 782 case "clear":
763 if (cmdparams.Length < 2) 783 if (cmdparams.Length < 2)
764 { 784 {
765 m_log.Warn("[FLOTSAM ASSET CACHE] Usage is fcache clear [file] [memory]"); 785 m_log.Warn("[FLOTSAM ASSET CACHE]: Usage is fcache clear [file] [memory]");
766 break; 786 break;
767 } 787 }
768 788
@@ -783,36 +803,48 @@ namespace Flotsam.RegionModules.AssetCache
783 803
784 if (clearMemory) 804 if (clearMemory)
785 { 805 {
786 m_MemoryCache.Clear(); 806 if (m_MemoryCacheEnabled)
787 m_log.Info("[FLOTSAM ASSET CACHE] Memory cache cleared."); 807 {
808 m_MemoryCache.Clear();
809 m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache cleared.");
810 }
811 else
812 {
813 m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache not enabled.");
814 }
788 } 815 }
789 816
790 if (clearFile) 817 if (clearFile)
791 { 818 {
792 ClearFileCache(); 819 if (m_FileCacheEnabled)
793 m_log.Info("[FLOTSAM ASSET CACHE] File cache cleared."); 820 {
821 ClearFileCache();
822 m_log.Info("[FLOTSAM ASSET CACHE]: File cache cleared.");
823 }
824 else
825 {
826 m_log.Info("[FLOTSAM ASSET CACHE]: File cache not enabled.");
827 }
794 } 828 }
795 829
796 break; 830 break;
797 831
798 832
799 case "assets": 833 case "assets":
800 m_log.Info("[FLOTSAM ASSET CACHE] Caching all assets, in all scenes."); 834 m_log.Info("[FLOTSAM ASSET CACHE]: Caching all assets, in all scenes.");
801 835
802 Util.FireAndForget(delegate { 836 Util.FireAndForget(delegate {
803 int assetsCached = CacheScenes(); 837 int assetsCached = CacheScenes();
804 m_log.InfoFormat("[FLOTSAM ASSET CACHE] Completed Scene Caching, {0} assets found.", assetsCached); 838 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Completed Scene Caching, {0} assets found.", assetsCached);
805 839
806 }); 840 });
807 841
808 break; 842 break;
809 843
810 case "expire": 844 case "expire":
811
812
813 if (cmdparams.Length < 3) 845 if (cmdparams.Length < 3)
814 { 846 {
815 m_log.InfoFormat("[FLOTSAM ASSET CACHE] Invalid parameters for Expire, please specify a valid date & time", cmd); 847 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Invalid parameters for Expire, please specify a valid date & time", cmd);
816 break; 848 break;
817 } 849 }
818 850
@@ -830,26 +862,28 @@ namespace Flotsam.RegionModules.AssetCache
830 862
831 if (!DateTime.TryParse(s_expirationDate, out expirationDate)) 863 if (!DateTime.TryParse(s_expirationDate, out expirationDate))
832 { 864 {
833 m_log.InfoFormat("[FLOTSAM ASSET CACHE] {0} is not a valid date & time", cmd); 865 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} is not a valid date & time", cmd);
834 break; 866 break;
835 } 867 }
836 868
837 CleanExpiredFiles(m_CacheDirectory, expirationDate); 869 if (m_FileCacheEnabled)
870 CleanExpiredFiles(m_CacheDirectory, expirationDate);
871 else
872 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache not active, not clearing.");
838 873
839 break; 874 break;
840 default: 875 default:
841 m_log.InfoFormat("[FLOTSAM ASSET CACHE] Unknown command {0}", cmd); 876 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Unknown command {0}", cmd);
842 break; 877 break;
843 } 878 }
844 } 879 }
845 else if (cmdparams.Length == 1) 880 else if (cmdparams.Length == 1)
846 { 881 {
847 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache status - Display cache status"); 882 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache status - Display cache status");
848 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearmem - Remove all assets cached in memory"); 883 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearmem - Remove all assets cached in memory");
849 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk"); 884 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearfile - Remove all assets cached on disk");
850 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache cachescenes - Attempt a deep cache of all assets in all scenes"); 885 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache cachescenes - Attempt a deep cache of all assets in all scenes");
851 m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache <datetime> - Purge assets older then the specified date & time"); 886 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache <datetime> - Purge assets older then the specified date & time");
852
853 } 887 }
854 } 888 }
855 889