Example #1
0
        /// <summary>
        /// Finds the <see cref="StudyStorageLocation"/> for the specified study
        /// </summary>
        /// <param name="studyInstanceUid"></param>
        /// <param name="partition"></param>
        /// <returns></returns>
        ///
        public StudyStorageLocation Find(string studyInstanceUid, ServerPartition partition)
        {
            TimeSpan             STATS_WINDOW = TimeSpan.FromMinutes(1);
            StudyStorageLocation location;

            if (!CacheEnabled)
            {
                FilesystemMonitor.Instance.GetReadableStudyStorageLocation(partition.Key, studyInstanceUid,
                                                                           StudyRestore.True, StudyCache.False,
                                                                           out location);
            }
            else
            {
                Session           session = _serverSessions[_sessionId];
                StudyStorageCache cache;
                lock (session)
                {
                    cache = session["StorageLocationCache"] as StudyStorageCache;

                    if (cache == null)
                    {
                        cache = new StudyStorageCache {
                            RetentionTime = CacheRetentionTime
                        };
                        session.Add("StorageLocationCache", cache);
                    }
                }

                // lock the cache instead of the list so that we won't block requests from other
                // clients if we need to fetch from the database.
                lock (cache)
                {
                    location = cache.Find(studyInstanceUid);
                    if (location == null)
                    {
                        _statistics.Misses++;

                        FilesystemMonitor.Instance.GetReadableStudyStorageLocation(partition.Key, studyInstanceUid, StudyRestore.True, StudyCache.False, out location);

                        cache.Insert(location, studyInstanceUid);
                        Platform.Log(LogLevel.Info, "Cache (since {0}): Hits {1} [{3:0}%], Miss {2}",
                                     _statistics.StartTime,
                                     _statistics.Hits, _statistics.Misses,
                                     (float)_statistics.Hits / (_statistics.Hits + _statistics.Misses) * 100f);
                    }
                    else
                    {
                        _statistics.Hits++;
                    }

                    if (_statistics.ElapsedTime > STATS_WINDOW)
                    {
                        _statistics.Reset();
                    }
                }
            }

            //TODO (CR April 2011): Should this be "not found"?
            if (location == null)
            {
                throw new StudyIsNearlineException(false);
            }

            return(location);
        }
Example #2
0
        /// <summary>
        /// Finds the <see cref="StudyStorageLocation"/> for the specified study
        /// </summary>
        /// <param name="studyInstanceUid"></param>
        /// <param name="partition"></param>
        /// <returns></returns>
        /// 
    	public StudyStorageLocation Find(string studyInstanceUid, ServerPartition partition)
        {
            TimeSpan STATS_WINDOW = TimeSpan.FromMinutes(1);
            StudyStorageLocation location;
            if (!CacheEnabled)
            {
            	FilesystemMonitor.Instance.GetReadableStudyStorageLocation(partition.Key, studyInstanceUid,
            	                                                           StudyRestore.True, StudyCache.False,
            	                                                           out location);
            }
            else
            {
                Session session = _serverSessions[_sessionId];
                StudyStorageCache cache;
                lock (session)
                {
                    cache = session["StorageLocationCache"] as StudyStorageCache;

                    if (cache == null)
                    {
                        cache = new StudyStorageCache {RetentionTime = CacheRetentionTime};
                    	session.Add("StorageLocationCache", cache);
                    }
                }

                // lock the cache instead of the list so that we won't block requests from other
                // clients if we need to fetch from the database.
                lock (cache)
                {
                    location = cache.Find(studyInstanceUid);
                    if (location == null)
                    {
                        _statistics.Misses++;
                        
						FilesystemMonitor.Instance.GetReadableStudyStorageLocation(partition.Key, studyInstanceUid, StudyRestore.True,StudyCache.False, out location);

						cache.Insert(location, studyInstanceUid);
                        Platform.Log(LogLevel.Info, "Cache (since {0}): Hits {1} [{3:0}%], Miss {2}",
                                         _statistics.StartTime,
                                         _statistics.Hits, _statistics.Misses,
                                         (float)_statistics.Hits / (_statistics.Hits + _statistics.Misses) * 100f);
                    }
                    else
                    {
                        _statistics.Hits++;
                    }

                    if (_statistics.ElapsedTime > STATS_WINDOW)
                    {
                        _statistics.Reset();
                    }

                }
            
            }

        	//TODO (CR April 2011): Should this be "not found"?
            if (location == null)
                throw new StudyIsNearlineException(false);
               
            return location;
		}