From 2a5b9f77408bfb0fd4e28e7bf28f59894525c365 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 29 Aug 2009 05:29:54 +0100 Subject: [PATCH] the beginning of some changes to the decode cache to address concerns about system load. This commit effectively disables expiration. --- .../Agent/TextureSender/J2KDecoderModule.cs | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index 00a247c2eb..df321a2aae 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs @@ -41,6 +41,8 @@ using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.CoreModules.Agent.TextureSender { + public delegate void J2KDecodeDelegate(UUID AssetId); + public class J2KDecoderModule : IRegionModule, IJ2KDecoder { #region IRegionModule Members @@ -437,15 +439,6 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender return false; } - DateTime creationTime = File.GetCreationTime(filename); - TimeSpan fileAge = DateTime.Now - creationTime; - - if (m_cacheTimeout != 0 && fileAge >= TimeSpan.FromMinutes(m_cacheTimeout)) - { - File.Delete(filename); - return false; - } - string readResult = string.Empty; try @@ -575,6 +568,16 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender return String.Format("j2kCache_{0}.cache", AssetId); } + public UUID AssetIdFromFileName(string fileName) + { + string rawId = fileName.Replace("j2kCache_", "").Replace(".cache", ""); + UUID asset; + if (!UUID.TryParse(rawId, out asset)) + return UUID.Zero; + + return asset; + } + /// /// Creates the Cache Folder /// @@ -639,5 +642,23 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender enabled = false; } } + + public void ScanCacheFiles(J2KDecodeDelegate decode) + { + DirectoryInfo dir = new DirectoryInfo(m_cacheDecodeFolder); + FileInfo[] files = dir.GetFiles("j2kCache_*.cache"); + + foreach (FileInfo f in files) + { + TimeSpan fileAge = DateTime.Now - f.CreationTime; + + if (m_cacheTimeout != 0 && fileAge >= TimeSpan.FromMinutes(m_cacheTimeout)) + { + File.Delete(f.Name); + decode(AssetIdFromFileName(f.Name)); + System.Threading.Thread.Sleep(2000); + } + } + } } }