diff options
author | Melanie Thielker | 2016-12-29 15:47:46 +0000 |
---|---|---|
committer | Melanie Thielker | 2016-12-29 15:47:46 +0000 |
commit | 07b48fd58c343d18b8ce64179e344439070511e8 (patch) | |
tree | 1a2bfb247699b8b6b94fa9d8146ee5341a08011f /OpenSim/Region/CoreModules | |
parent | Actually rename the file, too (diff) | |
download | opensim-SC_OLD-07b48fd58c343d18b8ce64179e344439070511e8.zip opensim-SC_OLD-07b48fd58c343d18b8ce64179e344439070511e8.tar.gz opensim-SC_OLD-07b48fd58c343d18b8ce64179e344439070511e8.tar.bz2 opensim-SC_OLD-07b48fd58c343d18b8ce64179e344439070511e8.tar.xz |
Add negative caching to flotsam cache. Prevents scripts from hammering the asset server
Diffstat (limited to 'OpenSim/Region/CoreModules')
4 files changed, 42 insertions, 0 deletions
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 | |||
221 | 221 | ||
222 | } | 222 | } |
223 | 223 | ||
224 | public void CacheNegative(string id) | ||
225 | { | ||
226 | // We don't do negative caching | ||
227 | } | ||
228 | |||
224 | /// <summary> | 229 | /// <summary> |
225 | /// Clear asset cache. | 230 | /// Clear asset cache. |
226 | /// </summary> | 231 | /// </summary> |
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 | |||
124 | m_Cache.Store(asset.ID, asset); | 124 | m_Cache.Store(asset.ID, asset); |
125 | } | 125 | } |
126 | 126 | ||
127 | public void CacheNegative(string id) | ||
128 | { | ||
129 | // We don't do negative caching | ||
130 | } | ||
131 | |||
127 | public AssetBase Get(string id) | 132 | public AssetBase Get(string id) |
128 | { | 133 | { |
129 | return (AssetBase)m_Cache.Get(id); | 134 | 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 | |||
92 | private ExpiringCache<string, AssetBase> m_MemoryCache; | 92 | private ExpiringCache<string, AssetBase> m_MemoryCache; |
93 | private bool m_MemoryCacheEnabled = false; | 93 | private bool m_MemoryCacheEnabled = false; |
94 | 94 | ||
95 | private ExpiringCache<string, object> m_negativeCache; | ||
96 | private bool m_negativeCacheEnabled = true; | ||
97 | private bool m_negativeCacheSliding = false; | ||
98 | |||
95 | // Expiration is expressed in hours. | 99 | // Expiration is expressed in hours. |
96 | private double m_MemoryExpiration = 0.016; | 100 | private double m_MemoryExpiration = 0.016; |
97 | private const double m_DefaultFileExpiration = 48; | 101 | private const double m_DefaultFileExpiration = 48; |
102 | // Negative cache is in seconds | ||
103 | private int m_negativeExpiration = 120; | ||
98 | private TimeSpan m_FileExpiration = TimeSpan.FromHours(m_DefaultFileExpiration); | 104 | private TimeSpan m_FileExpiration = TimeSpan.FromHours(m_DefaultFileExpiration); |
99 | private TimeSpan m_FileExpirationCleanupTimer = TimeSpan.FromHours(1.0); | 105 | private TimeSpan m_FileExpirationCleanupTimer = TimeSpan.FromHours(1.0); |
100 | 106 | ||
@@ -139,6 +145,7 @@ namespace OpenSim.Region.CoreModules.Asset | |||
139 | if (name == Name) | 145 | if (name == Name) |
140 | { | 146 | { |
141 | m_MemoryCache = new ExpiringCache<string, AssetBase>(); | 147 | m_MemoryCache = new ExpiringCache<string, AssetBase>(); |
148 | m_negativeCache = new ExpiringCache<string, object>(); | ||
142 | m_Enabled = true; | 149 | m_Enabled = true; |
143 | 150 | ||
144 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name); | 151 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name); |
@@ -158,6 +165,9 @@ namespace OpenSim.Region.CoreModules.Asset | |||
158 | m_MemoryExpiration = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration); | 165 | m_MemoryExpiration = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration); |
159 | m_MemoryExpiration *= 3600.0; // config in hours to seconds | 166 | m_MemoryExpiration *= 3600.0; // config in hours to seconds |
160 | 167 | ||
168 | m_negativeCacheEnabled = assetConfig.GetBoolean("NegativeCacheEnabled", m_negativeCacheEnabled); | ||
169 | m_negativeExpiration = assetConfig.GetInt("NegativeCacheTimeout", m_negativeExpiration); | ||
170 | m_negativeCacheSliding = assetConfig.GetBoolean("NegativeCacheSliding", m_negativeCacheSliding); | ||
161 | m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit); | 171 | m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit); |
162 | 172 | ||
163 | #if WAIT_ON_INPROGRESS_REQUESTS | 173 | #if WAIT_ON_INPROGRESS_REQUESTS |
@@ -355,6 +365,17 @@ namespace OpenSim.Region.CoreModules.Asset | |||
355 | } | 365 | } |
356 | } | 366 | } |
357 | 367 | ||
368 | public void CacheNegative(string id) | ||
369 | { | ||
370 | if (m_negativeCacheEnabled) | ||
371 | { | ||
372 | if (m_negativeCacheSliding) | ||
373 | m_negativeCache.AddOrUpdate(id, null, TimeSpan.FromSeconds(m_negativeExpiration)); | ||
374 | else | ||
375 | m_negativeCache.AddOrUpdate(id, null, m_negativeExpiration); | ||
376 | } | ||
377 | } | ||
378 | |||
358 | /// <summary> | 379 | /// <summary> |
359 | /// Updates the cached file with the current time. | 380 | /// Updates the cached file with the current time. |
360 | /// </summary> | 381 | /// </summary> |
@@ -514,6 +535,10 @@ namespace OpenSim.Region.CoreModules.Asset | |||
514 | { | 535 | { |
515 | m_Requests++; | 536 | m_Requests++; |
516 | 537 | ||
538 | object dummy; | ||
539 | if (m_negativeCache.TryGetValue(id, out dummy)) | ||
540 | return null; | ||
541 | |||
517 | AssetBase asset = null; | 542 | AssetBase asset = null; |
518 | asset = GetFromWeakReference(id); | 543 | asset = GetFromWeakReference(id); |
519 | if (asset != null && m_updateFileTimeOnCacheHit) | 544 | if (asset != null && m_updateFileTimeOnCacheHit) |
@@ -622,6 +647,8 @@ namespace OpenSim.Region.CoreModules.Asset | |||
622 | 647 | ||
623 | if (m_MemoryCacheEnabled) | 648 | if (m_MemoryCacheEnabled) |
624 | m_MemoryCache = new ExpiringCache<string, AssetBase>(); | 649 | m_MemoryCache = new ExpiringCache<string, AssetBase>(); |
650 | if (m_negativeCacheEnabled) | ||
651 | m_negativeCache = new ExpiringCache<string, object>(); | ||
625 | 652 | ||
626 | lock(weakAssetReferencesLock) | 653 | lock(weakAssetReferencesLock) |
627 | weakAssetReferences = new Dictionary<string, WeakReference>(); | 654 | weakAssetReferences = new Dictionary<string, WeakReference>(); |
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 | |||
126 | m_Cache.AddOrUpdate(asset.ID, asset); | 126 | m_Cache.AddOrUpdate(asset.ID, asset); |
127 | } | 127 | } |
128 | 128 | ||
129 | public void CacheNegative(string id) | ||
130 | { | ||
131 | // We don't do negative caching | ||
132 | } | ||
133 | |||
129 | public AssetBase Get(string id) | 134 | public AssetBase Get(string id) |
130 | { | 135 | { |
131 | Object asset = null; | 136 | Object asset = null; |