public void Clear() { if (m_logLevel >= 2) { MainConsole.Instance.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache."); } lock (m_fileCacheLock) { foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) { Directory.Delete(dir, true); } } if (m_MemoryCacheEnabled) { m_MemoryCache.Clear(); } IAssetMonitor monitor = (IAssetMonitor) m_simulationBase.ApplicationRegistry.RequestModuleInterface <IMonitorModule>().GetMonitor("", MonitorModuleHelper . AssetMonitor); if (monitor != null) { monitor.ClearAssetCacheStatistics(); } }
public void FinishedStartup() { IMonitorModule monitor = m_simulationBase.ApplicationRegistry.RequestModuleInterface <IMonitorModule>(); if (monitor != null) { _assetMonitor = monitor.GetMonitor <IAssetMonitor>(null); } }
public override AssetRef PackageAsset(object asset, IAssetMonitor monitor) { return(new AssetRef <PixelShader>((PixelShader)asset, this, monitor)); }
public AssetBase Get(string id) { m_Requests++; AssetBase asset = null; if (m_MemoryCacheEnabled && m_MemoryCache.TryGetValue(id, out asset)) { m_MemoryHits++; } else { string filename = GetFileName(id); lock (m_fileCacheLock) { if (File.Exists(filename)) { try { string file = File.ReadAllText(filename); asset = new AssetBase(); asset.Unpack(OpenMetaverse.StructuredData.OSDParser.DeserializeJson(file)); UpdateMemoryCache(id, asset); m_DiskHits++; } catch (SerializationException e) { LogException(e); // If there was a problem deserializing the asset, the asset may // either be corrupted OR was serialized under an old format // {different version of AssetBase} -- we should attempt to // delete it and re-cache File.Delete(filename); } catch (Exception e) { LogException(e); } } } #if WAIT_ON_INPROGRESS_REQUESTS // Check if we're already downloading this asset. If so, try to wait for it to // download. if (m_WaitOnInprogressTimeout > 0) { m_RequestsForInprogress++; ManualResetEvent waitEvent; if (m_CurrentlyWriting.TryGetValue(filename, out waitEvent)) { waitEvent.WaitOne(m_WaitOnInprogressTimeout); return(Get(id)); } } #else // Track how often we have the problem that an asset is requested while // it is still being downloaded by a previous request. if (m_CurrentlyWriting.Contains(filename)) { m_RequestsForInprogress++; } #endif } if (((m_logLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0)) { m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; MainConsole.Instance.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); MainConsole.Instance.InfoFormat("[FLOTSAM ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); if (m_MemoryCacheEnabled) { m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; MainConsole.Instance.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); } MainConsole.Instance.InfoFormat( "[FLOTSAM ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); } IAssetMonitor monitor = (IAssetMonitor) m_simulationBase.ApplicationRegistry.RequestModuleInterface <IMonitorModule>().GetMonitor("", MonitorModuleHelper . AssetMonitor); if (monitor != null) { monitor.AddAsset(asset); } return(asset); }
public abstract AssetRef PackageAsset(object asset, IAssetMonitor monitor);
public AssetRef(AssetTypeLoader loader, IAssetMonitor monitor) { m_loader = loader; m_assetMonitor = monitor; }