Mercurial > hg > orthanc
diff Core/Cache/SharedArchive.cpp @ 2976:cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Dec 2018 12:23:46 +0100 |
parents | 4dcafa8d6633 |
children | 4e43e67f8ecf |
line wrap: on
line diff
--- a/Core/Cache/SharedArchive.cpp Thu Dec 06 10:10:58 2018 +0100 +++ b/Core/Cache/SharedArchive.cpp Thu Dec 06 12:23:46 2018 +0100 @@ -47,6 +47,8 @@ { delete it->second; archive_.erase(it); + + lru_.Invalidate(id); } } @@ -59,7 +61,7 @@ if (it == that.archive_.end()) { - throw OrthancException(ErrorCode_InexistentItem); + item_ = NULL; } else { @@ -69,6 +71,20 @@ } + IDynamicObject& SharedArchive::Accessor::GetItem() const + { + if (item_ == NULL) + { + // "IsValid()" should have been called + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + return *item_; + } + } + + SharedArchive::SharedArchive(size_t maxSize) : maxSize_(maxSize) { @@ -96,12 +112,12 @@ if (archive_.size() == maxSize_) { // The quota has been reached, remove the oldest element - std::string oldest = lru_.RemoveOldest(); - RemoveInternal(oldest); + RemoveInternal(lru_.GetOldest()); } std::string id = Toolbox::GenerateUuid(); RemoveInternal(id); // Should never be useful because of UUID + archive_[id] = obj; lru_.Add(id); @@ -113,7 +129,6 @@ { boost::mutex::scoped_lock lock(mutex_); RemoveInternal(id); - lru_.Invalidate(id); } @@ -121,14 +136,14 @@ { items.clear(); - boost::mutex::scoped_lock lock(mutex_); + { + boost::mutex::scoped_lock lock(mutex_); - for (Archive::const_iterator it = archive_.begin(); - it != archive_.end(); ++it) - { - items.push_back(it->first); + for (Archive::const_iterator it = archive_.begin(); + it != archive_.end(); ++it) + { + items.push_back(it->first); + } } } } - -