Example #1
0
 public bool TryGetAsset(UUID assetId, out CacheEntry cachedAsset)
 {
     return _assetCache.TryGetValue(assetId, out cachedAsset);
 }
Example #2
0
        private AssetBase GetAssetInternal(OpenMetaverse.UUID assetID)
        {
            // Quick exit for null ID case.
            statTotal++;
            statGet++;
            if (assetID == OpenMetaverse.UUID.Zero)
            {
                statGetHit++;
                return(null);
            }

            //cache?
            Cache.CacheEntry cacheObject = null;
            lock (_assetCache)
            {
                _assetCache.TryGetAsset(assetID, out cacheObject);
            }

            StratusAsset rawAsset = null;

            if (cacheObject != null)
            {
                statGetHit++;
                //stream cache or asset cache?
                if (cacheObject.FullAsset != null)
                {
                    rawAsset = cacheObject.FullAsset;
                }
                else
                {
                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(cacheObject.Data, 0, cacheObject.Size))
                    {
                        rawAsset = DeserializeAssetFromStream(assetID, stream);
                    }
                }
            }
            else
            {
                StratusAsset diskAsset = null;
                if (!Config.Settings.Instance.DisableWritebackCache)
                {
                    diskAsset = _diskWriteBack.GetAsset(assetID.Guid);
                }

                if (diskAsset != null)
                {
                    rawAsset = diskAsset;
                }
                else
                {
                    Util.Retry(2, new List <Type> {
                        typeof(UnrecoverableAssetServerException)
                    }, () =>
                    {
                        ulong start = Util.GetLongTickCount();
                        CloudFilesAssetWorker worker = null;
                        try
                        {
                            try
                            {
                                //nothing on the local disk, request from CF
                                worker = _asyncAssetWorkers.LeaseObject();
                            }
                            catch (Exception e)
                            {
                                //exception here is unrecoverable since this is construction
                                statGetInit++;
                                throw new UnrecoverableAssetServerException(e.Message, e);
                            }

                            using (System.IO.MemoryStream stream = worker.GetAsset(assetID))
                            {
                                statGetFetches++;
                                stream.Position = 0;
                                rawAsset        = DeserializeAssetFromStream(assetID, stream);

                                //if we're using the cache, we need to put the raw data in there now
                                stream.Position = 0;
                                this.CacheAssetIfAppropriate(assetID, stream, rawAsset);
                            }
                        }
                        catch (net.openstack.Core.Exceptions.Response.ItemNotFoundException)
                        {
                            statGetNotFound++;
                            //not an exceptional case. this will happen
                            rawAsset = null;
                        }
                        finally
                        {
                            ulong elapsed = Util.GetLongTickCount() - start;
                            statGets.Add(elapsed);

                            if (worker != null)
                            {
                                _asyncAssetWorkers.ReturnObject(worker);
                            }
                        }
                    });
                }
            }

            //nothing?
            if (rawAsset == null)
            {
                return(null);
            }

            //convert
            return(rawAsset.ToAssetBase());
        }
Example #3
0
 void _assetCache_OnItemPurged(CacheEntry item)
 {
     if (item.Data != null)
     {
         _bufferPool.ReturnBytes(item.Data);
     }
 }