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