From 4b2e62fd3c347ec4d72762c19443e4a2765582f2 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 29 Aug 2009 04:35:18 +0100 Subject: Make the j2kDecodeCache expire after 50 minutes (configurable). Alse allows setting the path for it. This commit introduces NEW DEFAULT BEHAVIOR. To retain the old behavior (eternal cache) you will need to change your OpenSim.ini and set the timeout to 0. --- .../Agent/TextureSender/J2KDecoderModule.cs | 28 ++++++++++++++++++---- bin/OpenSim.ini.example | 7 ++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index 0d3cc23..00a247c 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 cff5d19..3529599 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 -- cgit v1.1