From 07b48fd58c343d18b8ce64179e344439070511e8 Mon Sep 17 00:00:00 2001
From: Melanie Thielker
Date: Thu, 29 Dec 2016 15:47:46 +0000
Subject: Add negative caching to flotsam cache. Prevents scripts from
hammering the asset server
---
.../Region/CoreModules/Asset/CenomeAssetCache.cs | 5 ++++
OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs | 5 ++++
.../Region/CoreModules/Asset/FlotsamAssetCache.cs | 27 ++++++++++++++++++++++
.../CoreModules/Asset/GlynnTuckerAssetCache.cs | 5 ++++
4 files changed, 42 insertions(+)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs
index 382b5f2..14b0280 100644
--- a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs
@@ -221,6 +221,11 @@ namespace OpenSim.Region.CoreModules.Asset
}
+ public void CacheNegative(string id)
+ {
+ // We don't do negative caching
+ }
+
///
/// Clear asset cache.
///
diff --git a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs
index d78b082..82bc5cc 100644
--- a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs
@@ -124,6 +124,11 @@ namespace OpenSim.Region.CoreModules.Asset
m_Cache.Store(asset.ID, asset);
}
+ public void CacheNegative(string id)
+ {
+ // We don't do negative caching
+ }
+
public AssetBase Get(string id)
{
return (AssetBase)m_Cache.Get(id);
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index fcd4252..84e13a0 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -92,9 +92,15 @@ namespace OpenSim.Region.CoreModules.Asset
private ExpiringCache m_MemoryCache;
private bool m_MemoryCacheEnabled = false;
+ private ExpiringCache m_negativeCache;
+ private bool m_negativeCacheEnabled = true;
+ private bool m_negativeCacheSliding = false;
+
// Expiration is expressed in hours.
private double m_MemoryExpiration = 0.016;
private const double m_DefaultFileExpiration = 48;
+ // Negative cache is in seconds
+ private int m_negativeExpiration = 120;
private TimeSpan m_FileExpiration = TimeSpan.FromHours(m_DefaultFileExpiration);
private TimeSpan m_FileExpirationCleanupTimer = TimeSpan.FromHours(1.0);
@@ -139,6 +145,7 @@ namespace OpenSim.Region.CoreModules.Asset
if (name == Name)
{
m_MemoryCache = new ExpiringCache();
+ m_negativeCache = new ExpiringCache();
m_Enabled = true;
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name);
@@ -158,6 +165,9 @@ namespace OpenSim.Region.CoreModules.Asset
m_MemoryExpiration = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration);
m_MemoryExpiration *= 3600.0; // config in hours to seconds
+ m_negativeCacheEnabled = assetConfig.GetBoolean("NegativeCacheEnabled", m_negativeCacheEnabled);
+ m_negativeExpiration = assetConfig.GetInt("NegativeCacheTimeout", m_negativeExpiration);
+ m_negativeCacheSliding = assetConfig.GetBoolean("NegativeCacheSliding", m_negativeCacheSliding);
m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit);
#if WAIT_ON_INPROGRESS_REQUESTS
@@ -355,6 +365,17 @@ namespace OpenSim.Region.CoreModules.Asset
}
}
+ public void CacheNegative(string id)
+ {
+ if (m_negativeCacheEnabled)
+ {
+ if (m_negativeCacheSliding)
+ m_negativeCache.AddOrUpdate(id, null, TimeSpan.FromSeconds(m_negativeExpiration));
+ else
+ m_negativeCache.AddOrUpdate(id, null, m_negativeExpiration);
+ }
+ }
+
///
/// Updates the cached file with the current time.
///
@@ -514,6 +535,10 @@ namespace OpenSim.Region.CoreModules.Asset
{
m_Requests++;
+ object dummy;
+ if (m_negativeCache.TryGetValue(id, out dummy))
+ return null;
+
AssetBase asset = null;
asset = GetFromWeakReference(id);
if (asset != null && m_updateFileTimeOnCacheHit)
@@ -622,6 +647,8 @@ namespace OpenSim.Region.CoreModules.Asset
if (m_MemoryCacheEnabled)
m_MemoryCache = new ExpiringCache();
+ if (m_negativeCacheEnabled)
+ m_negativeCache = new ExpiringCache();
lock(weakAssetReferencesLock)
weakAssetReferences = new Dictionary();
diff --git a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs
index 7343f4f..195bdaa 100644
--- a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs
@@ -126,6 +126,11 @@ namespace OpenSim.Region.CoreModules.Asset
m_Cache.AddOrUpdate(asset.ID, asset);
}
+ public void CacheNegative(string id)
+ {
+ // We don't do negative caching
+ }
+
public AssetBase Get(string id)
{
Object asset = null;
--
cgit v1.1