diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index 0d3cc23974..00a247c2eb 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs @@ -53,8 +53,9 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender /// private readonly Dictionary m_cacheddecode = new Dictionary(); private bool OpenJpegFail = false; - private readonly string CacheFolder = Util.dataDir() + "/j2kDecodeCache"; - private readonly J2KDecodeFileCache fCache; + private string CacheFolder = Util.dataDir() + "/j2kDecodeCache"; + private int CacheTimeout = 60; + private J2KDecodeFileCache fCache; /// /// List of client methods to notify of results of decode @@ -63,11 +64,19 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender public J2KDecoderModule() { - fCache = new J2KDecodeFileCache(CacheFolder); } public void Initialise(Scene scene, IConfigSource source) { + IConfig j2kConfig = source.Configs["J2KDecoder"]; + if (j2kConfig != null) + { + CacheFolder = j2kConfig.GetString("CacheDir", CacheFolder); + CacheTimeout = j2kConfig.GetInt("CacheTimeout", CacheTimeout); + } + + fCache = new J2KDecodeFileCache(CacheFolder, CacheTimeout); + scene.RegisterModuleInterface(this); } @@ -353,6 +362,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender public class J2KDecodeFileCache { private readonly string m_cacheDecodeFolder; + private readonly int m_cacheTimeout; private bool enabled = true; private static readonly ILog m_log @@ -362,9 +372,10 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender /// Creates a new instance of a file cache /// /// base folder for the cache. Will be created if it doesn't exist - public J2KDecodeFileCache(string pFolder) + public J2KDecodeFileCache(string pFolder, int timeout) { m_cacheDecodeFolder = pFolder; + m_cacheTimeout = timeout; if (!Directory.Exists(pFolder)) { Createj2KCacheFolder(pFolder); @@ -426,6 +437,15 @@ 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 diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index cff5d19097..3529599033 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -1366,6 +1366,13 @@ ; ;TextureDataLimit = 5 +;; The JPEG2000 decode cache +;; Timeout is in minutes + +[J2KDecoder] +;CacheDir = "./j2kDecodeCache" +;CacheTimeout = 60 + ;; ;; These are defaults that are overwritten below in [Architecture]. ;; These defaults allow OpenSim to work out of the box with