diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset')
-rw-r--r-- | OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 93 |
1 files changed, 53 insertions, 40 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 8aa173a..d1a563c 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | |||
@@ -253,57 +253,70 @@ namespace OpenSim.Region.CoreModules.Asset | |||
253 | 253 | ||
254 | private void UpdateFileCache(string key, AssetBase asset) | 254 | private void UpdateFileCache(string key, AssetBase asset) |
255 | { | 255 | { |
256 | string filename = GetFileName(asset.ID); | 256 | // TODO: Spawn this off to some seperate thread to do the actual writing |
257 | 257 | if (asset != null) | |
258 | try | ||
259 | { | 258 | { |
260 | // If the file is already cached just update access time. | 259 | string filename = GetFileName(key); |
261 | if (File.Exists(filename)) | 260 | |
262 | { | 261 | try |
263 | lock (m_CurrentlyWriting) | ||
264 | { | ||
265 | if (!m_CurrentlyWriting.Contains(filename)) | ||
266 | File.SetLastAccessTime(filename, DateTime.Now); | ||
267 | } | ||
268 | } | ||
269 | else | ||
270 | { | 262 | { |
271 | // Once we start writing, make sure we flag that we're writing | 263 | // If the file is already cached, don't cache it, just touch it so access time is updated |
272 | // that object to the cache so that we don't try to write the | 264 | if (File.Exists(filename)) |
273 | // same file multiple times. | ||
274 | lock (m_CurrentlyWriting) | ||
275 | { | 265 | { |
276 | #if WAIT_ON_INPROGRESS_REQUESTS | 266 | // We don't really want to know about sharing |
277 | if (m_CurrentlyWriting.ContainsKey(filename)) | 267 | // violations here. If the file is locked, then |
268 | // the other thread has updated the time for us. | ||
269 | try | ||
278 | { | 270 | { |
279 | return; | 271 | lock (m_CurrentlyWriting) |
272 | { | ||
273 | if (!m_CurrentlyWriting.Contains(filename)) | ||
274 | File.SetLastAccessTime(filename, DateTime.Now); | ||
275 | } | ||
280 | } | 276 | } |
281 | else | 277 | catch |
282 | { | ||
283 | m_CurrentlyWriting.Add(filename, new ManualResetEvent(false)); | ||
284 | } | ||
285 | |||
286 | #else | ||
287 | if (m_CurrentlyWriting.Contains(filename)) | ||
288 | { | 278 | { |
289 | return; | ||
290 | } | 279 | } |
291 | else | 280 | } else { |
281 | |||
282 | // Once we start writing, make sure we flag that we're writing | ||
283 | // that object to the cache so that we don't try to write the | ||
284 | // same file multiple times. | ||
285 | lock (m_CurrentlyWriting) | ||
292 | { | 286 | { |
293 | m_CurrentlyWriting.Add(filename); | 287 | #if WAIT_ON_INPROGRESS_REQUESTS |
294 | } | 288 | if (m_CurrentlyWriting.ContainsKey(filename)) |
289 | { | ||
290 | return; | ||
291 | } | ||
292 | else | ||
293 | { | ||
294 | m_CurrentlyWriting.Add(filename, new ManualResetEvent(false)); | ||
295 | } | ||
296 | |||
297 | #else | ||
298 | if (m_CurrentlyWriting.Contains(filename)) | ||
299 | { | ||
300 | return; | ||
301 | } | ||
302 | else | ||
303 | { | ||
304 | m_CurrentlyWriting.Add(filename); | ||
305 | } | ||
295 | #endif | 306 | #endif |
296 | } | ||
297 | 307 | ||
298 | Util.FireAndForget( | 308 | } |
299 | delegate { WriteFileCache(filename, asset); }); | 309 | |
310 | Util.FireAndForget( | ||
311 | delegate { WriteFileCache(filename, asset); }); | ||
312 | } | ||
313 | } | ||
314 | catch (Exception e) | ||
315 | { | ||
316 | m_log.ErrorFormat( | ||
317 | "[FLOTSAM ASSET CACHE]: Failed to update cache for asset {0}. Exception {1} {2}", | ||
318 | asset.ID, e.Message, e.StackTrace); | ||
300 | } | 319 | } |
301 | } | ||
302 | catch (Exception e) | ||
303 | { | ||
304 | m_log.ErrorFormat( | ||
305 | "[FLOTSAM ASSET CACHE]: Failed to update cache for asset {0}. Exception {1} {2}", | ||
306 | asset.ID, e.Message, e.StackTrace); | ||
307 | } | 320 | } |
308 | } | 321 | } |
309 | 322 | ||