elminate unnecessary asset != null check in FlotsamAssetCache.UpdateFileCache()

Passed in asset is always not null
master-beforevarregion
Justin Clark-Casey (justincc) 2014-01-18 00:06:12 +00:00
parent b52b50ee56
commit 12bfce7b9f
1 changed files with 51 additions and 54 deletions

View File

@ -248,71 +248,68 @@ namespace OpenSim.Region.CoreModules.Asset
private void UpdateFileCache(string key, AssetBase asset) private void UpdateFileCache(string key, AssetBase asset)
{ {
// TODO: Spawn this off to some seperate thread to do the actual writing string filename = GetFileName(key);
if (asset != null)
try
{ {
string filename = GetFileName(key); // If the file is already cached, don't cache it, just touch it so access time is updated
if (File.Exists(filename))
try
{ {
// If the file is already cached, don't cache it, just touch it so access time is updated // We don't really want to know about sharing
if (File.Exists(filename)) // violations here. If the file is locked, then
// the other thread has updated the time for us.
try
{ {
// We don't really want to know about sharing
// violations here. If the file is locked, then
// the other thread has updated the time for us.
try
{
lock (m_CurrentlyWriting)
{
if (!m_CurrentlyWriting.Contains(filename))
File.SetLastAccessTime(filename, DateTime.Now);
}
}
catch
{
}
} else {
// Once we start writing, make sure we flag that we're writing
// that object to the cache so that we don't try to write the
// same file multiple times.
lock (m_CurrentlyWriting) lock (m_CurrentlyWriting)
{ {
#if WAIT_ON_INPROGRESS_REQUESTS if (!m_CurrentlyWriting.Contains(filename))
if (m_CurrentlyWriting.ContainsKey(filename)) File.SetLastAccessTime(filename, DateTime.Now);
{
return;
}
else
{
m_CurrentlyWriting.Add(filename, new ManualResetEvent(false));
}
#else
if (m_CurrentlyWriting.Contains(filename))
{
return;
}
else
{
m_CurrentlyWriting.Add(filename);
}
#endif
} }
}
Util.FireAndForget( catch
delegate { WriteFileCache(filename, asset); }); {
} }
} }
catch (Exception e) else
{ {
m_log.ErrorFormat( // Once we start writing, make sure we flag that we're writing
"[FLOTSAM ASSET CACHE]: Failed to update cache for asset {0}. Exception {1} {2}", // that object to the cache so that we don't try to write the
asset.ID, e.Message, e.StackTrace); // same file multiple times.
lock (m_CurrentlyWriting)
{
#if WAIT_ON_INPROGRESS_REQUESTS
if (m_CurrentlyWriting.ContainsKey(filename))
{
return;
}
else
{
m_CurrentlyWriting.Add(filename, new ManualResetEvent(false));
}
#else
if (m_CurrentlyWriting.Contains(filename))
{
return;
}
else
{
m_CurrentlyWriting.Add(filename);
}
#endif
}
Util.FireAndForget(
delegate { WriteFileCache(filename, asset); });
} }
} }
catch (Exception e)
{
m_log.ErrorFormat(
"[FLOTSAM ASSET CACHE]: Failed to update cache for asset {0}. Exception {1} {2}",
asset.ID, e.Message, e.StackTrace);
}
} }
public void Cache(AssetBase asset) public void Cache(AssetBase asset)