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.
remotes/origin/0.6.7-post-fixes
Melanie 2009-08-29 04:35:18 +01:00
parent 976cf4284b
commit 4b2e62fd3c
2 changed files with 31 additions and 4 deletions

View File

@ -53,8 +53,9 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
/// </summary> /// </summary>
private readonly Dictionary<UUID, OpenJPEG.J2KLayerInfo[]> m_cacheddecode = new Dictionary<UUID, OpenJPEG.J2KLayerInfo[]>(); private readonly Dictionary<UUID, OpenJPEG.J2KLayerInfo[]> m_cacheddecode = new Dictionary<UUID, OpenJPEG.J2KLayerInfo[]>();
private bool OpenJpegFail = false; private bool OpenJpegFail = false;
private readonly string CacheFolder = Util.dataDir() + "/j2kDecodeCache"; private string CacheFolder = Util.dataDir() + "/j2kDecodeCache";
private readonly J2KDecodeFileCache fCache; private int CacheTimeout = 60;
private J2KDecodeFileCache fCache;
/// <summary> /// <summary>
/// List of client methods to notify of results of decode /// List of client methods to notify of results of decode
@ -63,11 +64,19 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
public J2KDecoderModule() public J2KDecoderModule()
{ {
fCache = new J2KDecodeFileCache(CacheFolder);
} }
public void Initialise(Scene scene, IConfigSource source) 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<IJ2KDecoder>(this); scene.RegisterModuleInterface<IJ2KDecoder>(this);
} }
@ -353,6 +362,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
public class J2KDecodeFileCache public class J2KDecodeFileCache
{ {
private readonly string m_cacheDecodeFolder; private readonly string m_cacheDecodeFolder;
private readonly int m_cacheTimeout;
private bool enabled = true; private bool enabled = true;
private static readonly ILog m_log private static readonly ILog m_log
@ -362,9 +372,10 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
/// Creates a new instance of a file cache /// Creates a new instance of a file cache
/// </summary> /// </summary>
/// <param name="pFolder">base folder for the cache. Will be created if it doesn't exist</param> /// <param name="pFolder">base folder for the cache. Will be created if it doesn't exist</param>
public J2KDecodeFileCache(string pFolder) public J2KDecodeFileCache(string pFolder, int timeout)
{ {
m_cacheDecodeFolder = pFolder; m_cacheDecodeFolder = pFolder;
m_cacheTimeout = timeout;
if (!Directory.Exists(pFolder)) if (!Directory.Exists(pFolder))
{ {
Createj2KCacheFolder(pFolder); Createj2KCacheFolder(pFolder);
@ -426,6 +437,15 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
return false; 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; string readResult = string.Empty;
try try

View File

@ -1366,6 +1366,13 @@
; ;
;TextureDataLimit = 5 ;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 are defaults that are overwritten below in [Architecture].
;; These defaults allow OpenSim to work out of the box with ;; These defaults allow OpenSim to work out of the box with