aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index b1bb56b..a0f1e8c 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -348,6 +348,17 @@ namespace OpenSim.Region.CoreModules.Asset
348 return asset; 348 return asset;
349 } 349 }
350 350
351 private bool CheckFromMemoryCache(string id)
352 {
353 AssetBase asset = null;
354
355 if (m_MemoryCache.TryGetValue(id, out asset))
356 return true;
357
358 return false;
359 }
360
361
351 /// <summary> 362 /// <summary>
352 /// Try to get an asset from the file cache. 363 /// Try to get an asset from the file cache.
353 /// </summary> 364 /// </summary>
@@ -420,6 +431,50 @@ namespace OpenSim.Region.CoreModules.Asset
420 return asset; 431 return asset;
421 } 432 }
422 433
434 private bool CheckFromFileCache(string id)
435 {
436 bool found = false;
437
438 string filename = GetFileName(id);
439 if (File.Exists(filename))
440 {
441 // actually check if we can open it, and so update expire
442 FileStream stream = null;
443 try
444 {
445 stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
446 if (stream != null)
447 {
448 found = true;
449 stream.Close();
450 }
451
452 }
453 catch (System.Runtime.Serialization.SerializationException e)
454 {
455 found = false;
456 m_log.ErrorFormat(
457 "[FLOTSAM ASSET CACHE]: Failed to check file {0} for asset {1}. Exception {2} {3}",
458 filename, id, e.Message, e.StackTrace);
459
460 // If there was a problem deserializing the asset, the asset may
461 // either be corrupted OR was serialized under an old format
462 // {different version of AssetBase} -- we should attempt to
463 // delete it and re-cache
464 File.Delete(filename);
465 }
466 catch (Exception e)
467 {
468 found = false;
469 m_log.ErrorFormat(
470 "[FLOTSAM ASSET CACHE]: Failed to check file {0} for asset {1}. Exception {2} {3}",
471 filename, id, e.Message, e.StackTrace);
472 }
473 }
474
475 return found;
476 }
477
423 public AssetBase Get(string id) 478 public AssetBase Get(string id)
424 { 479 {
425 m_Requests++; 480 m_Requests++;
@@ -456,11 +511,26 @@ namespace OpenSim.Region.CoreModules.Asset
456 return asset; 511 return asset;
457 } 512 }
458 513
514 public bool Check(string id)
515 {
516 if (m_MemoryCacheEnabled && CheckFromMemoryCache(id))
517 return true;
518
519 if (m_FileCacheEnabled && CheckFromFileCache(id))
520 return true;
521 return false;
522 }
523
459 public AssetBase GetCached(string id) 524 public AssetBase GetCached(string id)
460 { 525 {
461 return Get(id); 526 return Get(id);
462 } 527 }
463 528
529 public AssetBase CheckCached(string id)
530 {
531 return Get(id);
532 }
533
464 public void Expire(string id) 534 public void Expire(string id)
465 { 535 {
466 if (m_LogLevel >= 2) 536 if (m_LogLevel >= 2)
@@ -941,6 +1011,11 @@ namespace OpenSim.Region.CoreModules.Asset
941 return asset.Data; 1011 return asset.Data;
942 } 1012 }
943 1013
1014 public bool CheckData(string id)
1015 {
1016 return Check(id); ;
1017 }
1018
944 public bool Get(string id, object sender, AssetRetrieved handler) 1019 public bool Get(string id, object sender, AssetRetrieved handler)
945 { 1020 {
946 AssetBase asset = Get(id); 1021 AssetBase asset = Get(id);