changeset 6901:ce2494cb70ad streaming

integration mainline->streaming
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Jun 2026 07:41:56 +0200
parents 26f91b7e621d (diff) 4d044e9e0da1 (current diff)
children b8fe33ced80f
files OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 98 files changed, 3652 insertions(+), 2216 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Jun 01 22:56:23 2026 +0200
+++ b/.hgignore	Tue Jun 02 07:41:56 2026 +0200
@@ -2,8 +2,11 @@
 ThirdPartyDownloads/
 CMakeLists.txt.user
 *.cpp.orig
+*.cpp.rej
 *.h.orig
+*.h.rej
 *.patch.orig
+*.patch.rej
 .vs/
 .vscode/
 *~
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkConfiguration.cmake	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Resources/CMake/OrthancFrameworkConfiguration.cmake	Tue Jun 02 07:41:56 2026 +0200
@@ -404,7 +404,6 @@
       ${CMAKE_CURRENT_LIST_DIR}/../../Sources/Compression/HierarchicalZipWriter.cpp
       ${CMAKE_CURRENT_LIST_DIR}/../../Sources/Compression/ZipWriter.cpp
       ${CMAKE_CURRENT_LIST_DIR}/../../Sources/FileStorage/StorageAccessor.cpp
-      ${CMAKE_CURRENT_LIST_DIR}/../../Sources/FileStorage/StorageCache.cpp
       )
   endif()
 endif()
@@ -657,10 +656,12 @@
   list(APPEND ORTHANC_CORE_SOURCES_INTERNAL
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/Cache/MemoryStringCache.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/Cache/SharedArchive.cpp
+    ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/BaseDataIdentifier.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DataSourceAnswer.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DataSourceMemoryBudget.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DataSourceReader.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DataSourceRequest.cpp
+    ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DataSourceSequentialReader.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/StorageAreaDataSource.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/FileBuffer.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../../Sources/FileStorage/FilesystemStorage.cpp
@@ -681,6 +682,8 @@
   if (ENABLE_DCMTK)
     list(APPEND ORTHANC_CORE_SOURCES_INTERNAL
       ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DicomDataSource.cpp
+      ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DicomSequentialReader.cpp
+      ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/TranscoderDataSource.cpp
       )
   endif()
 
--- a/OrthancFramework/Sources/Cache/ICachePageProvider.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/ICachePageProvider.h	Tue Jun 02 07:41:56 2026 +0200
@@ -24,14 +24,16 @@
 
 #pragma once
 
+#include "../Compatibility.h"
+#include "../IDynamicObject.h"
+
 #include <string>
-#include "../IDynamicObject.h"
 
 namespace Orthanc
 {
   namespace Deprecated
   {
-    class ICachePageProvider
+    class ORTHANC_DEPRECATED_CLASS(ICachePageProvider)
     {
     public:
       virtual ~ICachePageProvider()
--- a/OrthancFramework/Sources/Cache/ICacheable.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/ICacheable.h	Tue Jun 02 07:41:56 2026 +0200
@@ -24,11 +24,13 @@
 
 #pragma once
 
+#include "../Compatibility.h"
+
 #include <boost/noncopyable.hpp>
 
 namespace Orthanc
 {
-  class ICacheable : public boost::noncopyable
+  class ORTHANC_DEPRECATED_CLASS(ICacheable) : public boost::noncopyable
   {
   public:
     virtual ~ICacheable()
--- a/OrthancFramework/Sources/Cache/MemoryCache.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/MemoryCache.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -22,11 +22,16 @@
  **/
 
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "../PrecompiledHeaders.h"
 #include "MemoryCache.h"
 
 #include "../Logging.h"
 
+
 namespace Orthanc
 {
   namespace Deprecated
--- a/OrthancFramework/Sources/Cache/MemoryCache.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/MemoryCache.h	Tue Jun 02 07:41:56 2026 +0200
@@ -37,7 +37,7 @@
     /**
      * WARNING: This class is NOT thread-safe.
      **/
-    class ORTHANC_PUBLIC MemoryCache : public boost::noncopyable
+    class ORTHANC_PUBLIC ORTHANC_DEPRECATED_CLASS(MemoryCache) : public boost::noncopyable
     {
     private:
       struct Page
--- a/OrthancFramework/Sources/Cache/MemoryObjectCache.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/MemoryObjectCache.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -22,6 +22,10 @@
  **/
 
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "../PrecompiledHeaders.h"
 #include "MemoryObjectCache.h"
 
--- a/OrthancFramework/Sources/Cache/MemoryObjectCache.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/MemoryObjectCache.h	Tue Jun 02 07:41:56 2026 +0200
@@ -42,7 +42,7 @@
   /**
    *  Note: this class is thread safe
    **/
-  class ORTHANC_PUBLIC MemoryObjectCache : public boost::noncopyable
+  class ORTHANC_PUBLIC ORTHANC_DEPRECATED_CLASS(MemoryObjectCache) : public boost::noncopyable
   {
   private:
     class Item;
@@ -82,7 +82,7 @@
 
     void Invalidate(const std::string& key);
 
-    class Accessor : public boost::noncopyable
+    class ORTHANC_PUBLIC Accessor : public boost::noncopyable
     {
     private:
 #if !defined(__EMSCRIPTEN__)
--- a/OrthancFramework/Sources/Cache/MemoryStringCache.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/MemoryStringCache.h	Tue Jun 02 07:41:56 2026 +0200
@@ -46,7 +46,7 @@
    * 
    * Note: this class is thread safe
    **/
-  class ORTHANC_PUBLIC MemoryStringCache : public boost::noncopyable
+  class ORTHANC_PUBLIC ORTHANC_DEPRECATED_CLASS(MemoryStringCache) : public boost::noncopyable
   {
   public:
     class ORTHANC_PUBLIC Accessor : public boost::noncopyable
--- a/OrthancFramework/Sources/Cache/SharedObjectCache.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/SharedObjectCache.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -189,4 +189,15 @@
 
     assert(!lru_.Contains(id));
   }
+
+
+  void SharedObjectCache::GetStatistics(size_t& capacity,
+                                        size_t& currentCount,
+                                        size_t& currentSize)
+  {
+    Mutex::ScopedLock lock(mutex_);
+    capacity = capacity_;
+    currentCount = lru_.GetSize();
+    currentSize = currentSize_;
+  }
 }
--- a/OrthancFramework/Sources/Cache/SharedObjectCache.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Cache/SharedObjectCache.h	Tue Jun 02 07:41:56 2026 +0200
@@ -69,5 +69,9 @@
                size_t size);
 
     void Invalidate(const std::string& id);
+
+    void GetStatistics(size_t& capacity,
+                       size_t& currentCount,
+                       size_t& currentSize);
   };
 }
--- a/OrthancFramework/Sources/Compatibility.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/Compatibility.h	Tue Jun 02 07:41:56 2026 +0200
@@ -47,6 +47,18 @@
 #endif
 
 
+// Macro "ORTHANC_DEPRECATED_CLASS" tags a class as having been deprecated
+#if (__cplusplus >= 201402L)  // C++14
+#  define ORTHANC_DEPRECATED_CLASS(f) [[deprecated]] f
+#elif defined(__GNUC__) || defined(__clang__)
+#  define ORTHANC_DEPRECATED_CLASS(f) __attribute__((deprecated)) f
+#elif defined(_MSC_VER)
+#  define ORTHANC_DEPRECATED_CLASS(f) __declspec(deprecated) f
+#else
+#  define ORTHANC_DEPRECATED
+#endif
+
+
 // Macros "ORTHANC_OVERRIDE" and "ORTHANC_FINAL" wrap the "override"
 // and "final" keywords introduced in C++11, to do compile-time
 // checking of virtual methods
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/BaseDataIdentifier.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,78 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeaders.h"
+#include "BaseDataIdentifier.h"
+
+#include "../OrthancException.h"
+
+
+namespace Orthanc
+{
+  void BaseDataIdentifier::SetUserData(IDynamicObject* userData)
+  {
+    std::unique_ptr<IDynamicObject> protection(userData);
+
+    if (userData == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      userData_.reset(protection.release());
+    }
+  }
+
+
+  bool BaseDataIdentifier::HasUserData() const
+  {
+    return userData_.get() != NULL;
+  }
+
+
+  const IDynamicObject& BaseDataIdentifier::GetUserData() const
+  {
+    if (userData_.get() != NULL)
+    {
+      return *userData_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
+  IDynamicObject* BaseDataIdentifier::ReleaseUserData()
+  {
+    if (userData_.get() != NULL)
+    {
+      return userData_.release();
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/BaseDataIdentifier.h	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,47 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IDataIdentifier.h"
+#include "../Compatibility.h"
+
+
+namespace Orthanc
+{
+  class ORTHANC_PUBLIC BaseDataIdentifier : public IDataIdentifier
+  {
+  private:
+    std::unique_ptr<IDynamicObject> userData_;
+
+  public:
+    void SetUserData(IDynamicObject* userData);
+
+    virtual bool HasUserData() const ORTHANC_OVERRIDE;
+
+    virtual const IDynamicObject& GetUserData() const ORTHANC_OVERRIDE;
+
+    virtual IDynamicObject* ReleaseUserData() ORTHANC_OVERRIDE;
+  };
+}
--- a/OrthancFramework/Sources/DataSource/DataSourceAnswer.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceAnswer.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -75,10 +75,17 @@
 
   const IDataIdentifier& DataSourceAnswer::Item::GetId() const
   {
-    assert(id_.get() != NULL);
-    return *id_;
+    if (id_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return *id_;
+    }
   }
 
+
   const boost::shared_ptr<IDynamicObject>& DataSourceAnswer::Item::GetValue() const
   {
     if (error_)
--- a/OrthancFramework/Sources/DataSource/DataSourceAnswer.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceAnswer.h	Tue Jun 02 07:41:56 2026 +0200
@@ -75,6 +75,16 @@
       const IDataIdentifier& GetId() const;
 
       const boost::shared_ptr<IDynamicObject>& GetValue() const;
+
+      bool HasUserData() const
+      {
+        return id_->HasUserData();
+      }
+
+      IDynamicObject* ReleaseUserData()
+      {
+        return id_->ReleaseUserData();
+      }
     };
 
   private:
--- a/OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -72,5 +72,17 @@
       boost::mutex::scoped_lock lock(mutex_);
       return currentMemory_;
     }
+
+
+    void DataSourceMemoryBudget::GetStatistics(uint64_t& maximumMemory,
+                                               uint64_t& currentMemory,
+                                               unsigned int& countReservations)
+
+    {
+      boost::mutex::scoped_lock lock(mutex_);
+      maximumMemory = maximumMemory_;
+      currentMemory = currentMemory_;
+      countReservations = reservations_;
+    }
   }
 }
--- a/OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceMemoryBudget.h	Tue Jun 02 07:41:56 2026 +0200
@@ -29,6 +29,7 @@
 #endif
 
 #include "../Compatibility.h"
+#include "../OrthancFramework.h"
 
 #include <boost/noncopyable.hpp>
 #include <boost/thread/condition_variable.hpp>
@@ -41,7 +42,7 @@
   namespace Internals
   {
     // This is basically a semaphore with the uint64_t data type
-    class DataSourceMemoryBudget : public boost::noncopyable
+    class ORTHANC_PUBLIC DataSourceMemoryBudget : public boost::noncopyable
     {
     private:
       boost::mutex               mutex_;
@@ -59,7 +60,7 @@
 
       uint64_t GetCurrentMemory() ORTHANC_NOEXCEPT;
 
-      class Lock : public boost::noncopyable
+      class ORTHANC_PUBLIC Lock : public boost::noncopyable
       {
       private:
         DataSourceMemoryBudget&  that_;
@@ -79,6 +80,10 @@
           that_.Release(memory_);
         }
       };
+
+      void GetStatistics(uint64_t& maximumMemory,
+                         uint64_t& currentMemory,
+                         unsigned int& countReservations);
     };
   }
 }
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -26,6 +26,8 @@
 #include "DataSourceReader.h"
 
 #include "../Cache/SharedObjectCache.h"
+#include "../Constants.h"
+#include "../MetricsRegistry.h"
 #include "../OrthancException.h"
 #include "DataSourceMemoryBudget.h"
 
@@ -36,6 +38,70 @@
 
 namespace Orthanc
 {
+  DataSourceReader::MetricsConfiguration::MetricsConfiguration(const boost::shared_ptr<MetricsRegistry>& metrics,
+                                                               const std::string& cacheSizeMegabytesName,
+                                                               const std::string& cacheCountName,
+                                                               const std::string& cacheHitCountName,
+                                                               const std::string& cacheMissCountName)
+  {
+    if (metrics.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else if (cacheSizeMegabytesName.empty() ||
+             cacheCountName.empty() ||
+             cacheHitCountName.empty() ||
+             cacheMissCountName.empty())
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      metrics_ = metrics;
+      cacheSizeMegabytesName_ = cacheSizeMegabytesName;
+      cacheCountName_ = cacheCountName;
+      cacheHitCountName_ = cacheHitCountName;
+      cacheMissCountName_ = cacheMissCountName;
+
+      metrics_->SetFloatValue(cacheSizeMegabytesName_, 0);
+      metrics_->SetIntegerValue(cacheCountName_, 0);
+      metrics_->SetIntegerValue(cacheHitCountName_, 0);
+      metrics_->SetIntegerValue(cacheMissCountName_, 0);
+    }
+  }
+
+
+  void DataSourceReader::MetricsConfiguration::SetCacheStatistics(SharedObjectCache& cache)
+  {
+    if (metrics_)
+    {
+      size_t capacity, count, size;
+      cache.GetStatistics(capacity, count, size);
+
+      metrics_->SetFloatValue(cacheSizeMegabytesName_, static_cast<float>(size) / static_cast<float>(MEGABYTE));
+      metrics_->SetIntegerValue(cacheCountName_, count);
+    }
+  }
+
+
+  void DataSourceReader::MetricsConfiguration::IncrementCacheHitCount()
+  {
+    if (metrics_)
+    {
+      metrics_->IncrementIntegerValue(cacheHitCountName_, 1);
+    }
+  }
+
+
+  void DataSourceReader::MetricsConfiguration::IncrementCacheMissCount()
+  {
+    if (metrics_)
+    {
+      metrics_->IncrementIntegerValue(cacheMissCountName_, 1);
+    }
+  }
+
+
   class DataSourceReader::DataSourceRunnable : public IRunnable
   {
   private:
@@ -44,18 +110,21 @@
     std::unique_ptr<IDataIdentifier>                      id_;
     boost::shared_ptr<SharedObjectCache>                  cache_;
     boost::shared_ptr<Internals::DataSourceMemoryBudget>  budget_;
+    MetricsConfiguration                                  metricsConfiguration_;
 
   public:
-    DataSourceRunnable(boost::shared_ptr<DataSourceAnswer>& answer,
+    DataSourceRunnable(const boost::shared_ptr<DataSourceAnswer>& answer,
                        IDataSource& source,
                        IDataIdentifier* id,
                        boost::shared_ptr<SharedObjectCache>& cache,
-                       boost::shared_ptr<Internals::DataSourceMemoryBudget>& budget) :
+                       boost::shared_ptr<Internals::DataSourceMemoryBudget>& budget,
+                       const MetricsConfiguration& metrics) :
       answer_(answer),
       source_(source),
       id_(id),
       cache_(cache),
-      budget_(budget)
+      budget_(budget),
+      metricsConfiguration_(metrics)
     {
       if (id == NULL ||
           answer.get() == NULL)
@@ -66,7 +135,17 @@
 
     virtual void Run() ORTHANC_OVERRIDE
     {
-      // Phase 1: Do all the work WITHOUT holding a strong reference to "DataSourceAnswer".
+      // Phase 1: Make sure the target answer is still alive before doing unnecessary work.
+      {
+        boost::shared_ptr<DataSourceAnswer> lock = answer_.lock();
+        if (!lock)
+        {
+          // The answer was abandonned, give up the request
+          return;
+        }
+      }
+
+      // Phase 2: Do all the work WITHOUT holding a strong reference to "DataSourceAnswer".
       boost::shared_ptr<IDynamicObject> value;
       std::unique_ptr<OrthancException> error;
 
@@ -80,6 +159,15 @@
         if (cache_ && hasCacheKey)
         {
           value = cache_->GetCachedValue(cacheKey);
+
+          if (value)
+          {
+            metricsConfiguration_.IncrementCacheHitCount();
+          }
+          else
+          {
+            metricsConfiguration_.IncrementCacheMissCount();
+          }
         }
 
         if (!value)
@@ -94,7 +182,7 @@
 
           value.reset(source_.Load(*id_));
 
-          if (!error && !value)
+          if (!value)
           {
             error.reset(new OrthancException(ErrorCode_NullPointer));
           }
@@ -102,6 +190,7 @@
           if (!error && cache_ && hasCacheKey)
           {
             cache_->Store(cacheKey, value, source_.GetValueSize(*value));
+            metricsConfiguration_.SetCacheStatistics(*cache_);
           }
         }
 
@@ -119,7 +208,7 @@
         error.reset(new OrthancException(ErrorCode_InternalError));
       }
 
-      // Phase 2: Acquire budget WITHOUT holding a strong reference to "DataSourceAnswer".
+      // Phase 3: Acquire budget WITHOUT holding a strong reference to "DataSourceAnswer".
       // If the "DataSourceAnswer" has been dropped, "answer_.lock()" below will return NULL
       // and we will immediately "Release()" to revert this.
       if (!error)
@@ -127,7 +216,7 @@
         budget_->Acquire(size);   // may block; "DataSourceAnswer" CAN be destroyed here
       }
 
-      // Phase 3: Only now take a strong reference to "DataSourceAnswer".
+      // Phase 4: Only now take a strong reference to "DataSourceAnswer".
       {
         boost::shared_ptr<DataSourceAnswer> lock = answer_.lock();
 
@@ -156,13 +245,13 @@
   };
 
 
-  DataSourceReader::DataSourceReader(IExecutorService* executor /* takes ownership */,
+  DataSourceReader::DataSourceReader(const boost::shared_ptr<IExecutorService>& executor /* takes ownership */,
                                      IDataSource* source /* takes ownership */) :
     executor_(executor),
     source_(source),
     budget_(new Internals::DataSourceMemoryBudget(0))
   {
-    if (executor == NULL ||
+    if (executor.get() == NULL ||
         source == NULL)
     {
       throw OrthancException(ErrorCode_NullPointer);
@@ -185,7 +274,7 @@
   }
 
 
-  void DataSourceReader::SetMaximumMemory(uint64_t maximumMemory)
+  void DataSourceReader::SetCapacity(uint64_t maximumMemory)
   {
     budget_ = boost::make_shared<Internals::DataSourceMemoryBudget>(maximumMemory);
   }
@@ -200,14 +289,14 @@
     while (!protection->IsEmpty())
     {
       std::unique_ptr<IDataIdentifier> identifier(protection->Dequeue());
-      executor_->Submit(new DataSourceRunnable(answer, *source_, identifier.release(), cache_, budget_));
+      executor_->Submit(new DataSourceRunnable(answer, *source_, identifier.release(), cache_, budget_, metricsConfiguration_));
     }
 
     return answer;
   }
 
 
-  boost::shared_ptr<IDynamicObject> DataSourceReader::ReadSingle(IDataIdentifier* id)
+  DataSourceAnswer::Item* DataSourceReader::ReadSingle(IDataIdentifier* id /* takes ownership */)
   {
     std::unique_ptr<IDataIdentifier> protection(id);
 
@@ -217,8 +306,20 @@
     boost::shared_ptr<DataSourceAnswer> answer(Submit(request.release()));
 
     std::unique_ptr<DataSourceAnswer::Item> item(answer->Dequeue());
+    assert(item != NULL);
     assert(answer->Dequeue() == NULL);
 
-    return item->GetValue();
+    return item.release();
+  }
+
+
+  void DataSourceReader::GetStatistics(uint64_t& tasksMaximumMemory,
+                                       uint64_t& tasksCurrentMemory,
+                                       unsigned int& tasksReservations)
+  {
+    {
+      boost::shared_ptr<Internals::DataSourceMemoryBudget> budgetCopy(budget_);
+      budgetCopy->GetStatistics(tasksMaximumMemory, tasksCurrentMemory, tasksReservations);
+    }
   }
 }
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.h	Tue Jun 02 07:41:56 2026 +0200
@@ -34,6 +34,7 @@
 
 namespace Orthanc
 {
+  class MetricsRegistry;
   class SharedObjectCache;
 
   namespace Internals
@@ -43,36 +44,81 @@
 
   class ORTHANC_PUBLIC DataSourceReader : public boost::noncopyable
   {
+  public:
+    class MetricsConfiguration
+    {
+    private:
+      boost::shared_ptr<MetricsRegistry>  metrics_;
+      std::string                         cacheSizeMegabytesName_;
+      std::string                         cacheCountName_;
+      std::string                         cacheHitCountName_;
+      std::string                         cacheMissCountName_;
+
+    public:
+      MetricsConfiguration()
+      {
+      }
+
+      MetricsConfiguration(const boost::shared_ptr<MetricsRegistry>& metrics,
+                           const std::string& cacheSizeMegabytesName,
+                           const std::string& cacheCountName,
+                           const std::string& cacheHitCountName,
+                           const std::string& cacheMissCountName);
+
+      void SetCacheStatistics(SharedObjectCache& cache);
+
+      void IncrementCacheHitCount();
+
+      void IncrementCacheMissCount();
+    };
+
   private:
     class DataSourceRunnable;
 
-    std::unique_ptr<IExecutorService>                     executor_;
+    boost::shared_ptr<IExecutorService>                   executor_;
     std::unique_ptr<IDataSource>                          source_;
     boost::shared_ptr<SharedObjectCache>                  cache_;
     boost::shared_ptr<Internals::DataSourceMemoryBudget>  budget_;
+    MetricsConfiguration                                  metricsConfiguration_;
 
   public:
-    DataSourceReader(IExecutorService* executor /* takes ownership */,
+    DataSourceReader(const boost::shared_ptr<IExecutorService>& executor,
                      IDataSource* source /* takes ownership */);
 
     ~DataSourceReader();
 
-    IDataSource& GetSource() const
+    void SetMetricsConfiguration(const MetricsConfiguration& configuration)
     {
-      return *source_;
+      metricsConfiguration_ = configuration;
     }
 
     void CreateCache(size_t capacity);
 
-    void SetMaximumMemory(uint64_t maximumMemory);
+    /**
+     * Apply backpressure by limiting memory for pending read
+     * tasks. Further reads block until memory is released.
+     **/
+    void SetCapacity(uint64_t maximumMemory);
 
+    /**
+     * Request the data source to load a set of items. The values will
+     * be read in parallel by a thread pool (cf. "executor_") and will
+     * be answered in no specific order through a message queue
+     * (cf. class "DataSourceAnswer"). The user data stored in
+     * "IDataIdentifier" can be used to identify items. If order is
+     * important, use the class "DataSourceSequentialReader" instead.
+     **/
     boost::shared_ptr<DataSourceAnswer> Submit(DataSourceRequest* request /* takes ownership */);
 
-    boost::shared_ptr<IDynamicObject> ReadSingle(IDataIdentifier* id /* takes ownership */);
+    DataSourceAnswer::Item* ReadSingle(IDataIdentifier* id /* takes ownership */);
 
     void Stop()
     {
       executor_->Stop();
     }
+
+    void GetStatistics(uint64_t& tasksMaximumMemory,
+                       uint64_t& tasksCurrentMemory,
+                       unsigned int& tasksReservations);
   };
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/DataSourceSequentialReader.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,336 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeaders.h"
+#include "DataSourceSequentialReader.h"
+
+#include "DataSourceReader.h"
+#include "../OrthancException.h"
+
+namespace Orthanc
+{
+  DataSourceSequentialReader::Item::Item(IDynamicObject* value,
+                                         size_t estimatedSize) :
+    value_(value),
+    estimatedSize_(estimatedSize)
+  {
+    if (value == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+  }
+
+
+  DataSourceSequentialReader::Item::Item(const OrthancException& error) :
+    error_(new OrthancException(error)),
+    estimatedSize_(0)
+  {
+  }
+
+
+  const IDynamicObject& DataSourceSequentialReader::Item::GetValue() const
+  {
+    if (value_.get() != NULL)
+    {
+      assert(error_.get() == NULL);
+      return *value_;
+    }
+    else if (error_.get() != NULL)
+    {
+      throw *error_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
+  void DataSourceSequentialReader::Item::SetUserData(IDynamicObject* userData)
+  {
+    if (userData == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      userData_.reset(userData);
+    }
+  }
+
+
+  const IDynamicObject& DataSourceSequentialReader::Item::GetUserData() const
+  {
+    if (userData_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return *userData_;
+    }
+  }
+
+
+  IDynamicObject* DataSourceSequentialReader::Item::ReleaseValue()
+  {
+    if (value_.get() != NULL)
+    {
+      assert(error_.get() == NULL);
+      return value_.release();
+    }
+    else if (error_.get() != NULL)
+    {
+      throw *error_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
+  IDynamicObject* DataSourceSequentialReader::Item::ReleaseUserData()
+  {
+    if (userData_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return userData_.release();
+    }
+  }
+
+
+  class DataSourceSequentialReader::Callable : public ICallable
+  {
+  private:
+    boost::shared_ptr<DataSourceReader>    reader_;
+    boost::shared_ptr<IValueDisconnector>  disconnector_;
+    std::unique_ptr<IDataIdentifier>       request_;
+    size_t                                 estimatedSize_;
+
+  public:
+    Callable(const boost::shared_ptr<DataSourceReader>& reader,
+             const boost::shared_ptr<IValueDisconnector>& disconnector,
+             IDataIdentifier* request,
+             size_t estimatedSize) :
+      reader_(reader),
+      disconnector_(disconnector),
+      request_(request),
+      estimatedSize_(estimatedSize)
+    {
+      if (reader.get() == NULL ||
+          disconnector.get() == NULL ||
+          request_ == NULL)
+      {
+        throw OrthancException(ErrorCode_NullPointer);
+      }
+    }
+
+    virtual IDynamicObject* Call() ORTHANC_OVERRIDE
+    {
+      std::unique_ptr<DataSourceAnswer::Item> answer(reader_->ReadSingle(request_.release()));
+
+      std::unique_ptr<IDynamicObject> userData;
+
+      if (answer->HasUserData())
+      {
+        userData.reset(answer->ReleaseUserData());
+      }
+
+      std::unique_ptr<Item> item;
+
+      try
+      {
+        std::unique_ptr<IDynamicObject> detached(disconnector_->Apply(answer.release()));
+        if (detached.get() == NULL)
+        {
+          throw OrthancException(ErrorCode_NullPointer);
+        }
+
+        item.reset(new Item(detached.release(), estimatedSize_));
+      }
+      catch (OrthancException& e)
+      {
+        item.reset(new Item(e));
+      }
+      catch (...)
+      {
+        item.reset(new Item(OrthancException(ErrorCode_InternalError)));
+      }
+
+      if (userData.get() != NULL)
+      {
+        item->SetUserData(userData.release());
+      }
+
+      return item.release();
+    }
+  };
+
+
+  void DataSourceSequentialReader::FillWindow()
+  {
+    while (!pendingRequests_.empty() &&
+           runningRequests_.size() < windowSize_)
+    {
+      size_t estimatedSize;
+      if (pendingRequests_.front()->EstimateValueSize(estimatedSize))
+      {
+        // Ensure that at least 1 callable is running even if too large for capacity
+        if (!runningRequests_.empty() &&
+            windowCapacity_ != 0 &&
+            runningSize_ + estimatedSize > windowCapacity_)
+        {
+          return;
+        }
+      }
+      else
+      {
+        estimatedSize = 0;
+      }
+
+      std::unique_ptr<IDataIdentifier> front(pendingRequests_.front());
+      pendingRequests_.pop_front();
+
+      runningSize_ += estimatedSize;
+
+      std::unique_ptr<ICallable> callable(new Callable(reader_, disconnector_, front.release(), estimatedSize));
+      runningRequests_.push_back(executor_->Submit(callable.release()));
+    }
+  }
+
+
+  DataSourceSequentialReader::DataSourceSequentialReader(const boost::shared_ptr<IExecutorService>& executor,
+                                                         const boost::shared_ptr<DataSourceReader>& reader,
+                                                         IValueDisconnector* disconnector /* takes ownership */,
+                                                         unsigned int windowSize,
+                                                         uint64_t windowCapacity) :
+    executor_(executor),
+    reader_(reader),
+    disconnector_(disconnector),
+    windowSize_(windowSize),
+    windowCapacity_(windowCapacity),
+    started_(false),
+    runningSize_(0)
+  {
+    if (executor.get() == NULL ||
+        reader.get() == NULL ||
+        disconnector == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+
+    if (windowSize == 0)
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
+  DataSourceSequentialReader::~DataSourceSequentialReader()
+  {
+    for (PendingRequests::iterator it = pendingRequests_.begin(); it != pendingRequests_.end(); ++it)
+    {
+      assert(*it != NULL);
+      delete *it;
+    }
+
+    for (RunningRequests::iterator it = runningRequests_.begin(); it != runningRequests_.end(); ++it)
+    {
+      assert(*it != NULL);
+      delete *it;
+    }
+  }
+
+
+  void DataSourceSequentialReader::Submit(IDataIdentifier* request /* takes ownership */)
+  {
+    std::unique_ptr<IDataIdentifier> protection(request);
+
+    if (request == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else if (started_)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      pendingRequests_.push_back(protection.release());
+    }
+  }
+
+
+  void DataSourceSequentialReader::Start()
+  {
+    if (started_)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      started_ = true;
+      FillWindow();
+    }
+  }
+
+
+  bool DataSourceSequentialReader::HasNext() const
+  {
+    if (!started_)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return !runningRequests_.empty();
+    }
+  }
+
+
+  DataSourceSequentialReader::Item* DataSourceSequentialReader::Next()
+  {
+    if (!started_ ||
+        !HasNext())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      std::unique_ptr<Future> future(runningRequests_.front());
+      runningRequests_.pop_front();
+
+      std::unique_ptr<Item> item(dynamic_cast<Item*>(future->ReleaseResult()));
+      runningSize_ -= item->GetEstimatedSize();
+
+      FillWindow();
+
+      return item.release();
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/DataSourceSequentialReader.h	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,143 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "../MultiThreading/IExecutorService.h"
+#include "DataSourceAnswer.h"
+
+
+namespace Orthanc
+{
+  class DataSourceReader;
+  class OrthancException;
+
+  /**
+   * This class retrieves items from a data source in a deterministic
+   * order while still using parallel execution through a thread pool.
+   *
+   * Internally, it uses a sliding-window approach. Since items may
+   * complete out of order, the class buffers them until earlier items
+   * become available. This additional buffering is necessary because
+   * applying backpressure (as done in "DataSourceReader::Submit()")
+   * could otherwise lead to deadlock. If item ordering is not
+   * required, prefer "DataSourceReader::Submit()", which supports
+   * backpressure and avoids the extra memory overhead.
+   *
+   * Note that this class is not thread safe, it should be invoked
+   * from a single thread.
+   **/
+  class ORTHANC_PUBLIC DataSourceSequentialReader : public boost::noncopyable
+  {
+  public:
+    class ORTHANC_PUBLIC Item : public IDynamicObject
+    {
+    private:
+      std::unique_ptr<IDynamicObject>    value_;
+      std::unique_ptr<OrthancException>  error_;
+      std::unique_ptr<IDynamicObject>    userData_;
+      size_t                             estimatedSize_;
+
+    public:
+      Item(IDynamicObject* value,
+           size_t estimatedSize);
+
+      explicit Item(const OrthancException& error);
+
+      const IDynamicObject& GetValue() const;
+
+      void SetUserData(IDynamicObject* userData);
+
+      bool HasUserData() const
+      {
+        return userData_.get() != NULL;
+      }
+
+      const IDynamicObject& GetUserData() const;
+
+      size_t GetEstimatedSize() const
+      {
+        return estimatedSize_;
+      }
+
+      IDynamicObject* ReleaseValue();
+
+      IDynamicObject* ReleaseUserData();
+    };
+
+
+    /**
+     * Extracts the value from an answer item so that it can be
+     * buffered independently and is no longer subject to
+     * backpressure.
+     **/
+    class ORTHANC_PUBLIC IValueDisconnector : public boost::noncopyable
+    {
+    public:
+      virtual ~IValueDisconnector()
+      {
+      }
+
+      // Note that "source" will never contain user data, those are handled at the level above
+      virtual IDynamicObject* Apply(DataSourceAnswer::Item* source) = 0;
+    };
+
+
+  private:
+    class Callable;
+
+    typedef std::list<IDataIdentifier*>  PendingRequests;
+    typedef std::list<Future*>           RunningRequests;
+
+    boost::shared_ptr<IExecutorService>    executor_;
+    boost::shared_ptr<DataSourceReader>    reader_;
+    boost::shared_ptr<IValueDisconnector>  disconnector_;
+    unsigned int                           windowSize_;
+    uint64_t                               windowCapacity_;
+
+    bool             started_;
+    PendingRequests  pendingRequests_;
+    RunningRequests  runningRequests_;
+    uint64_t         runningSize_;
+
+    void FillWindow();
+
+  public:
+    DataSourceSequentialReader(const boost::shared_ptr<IExecutorService>& executor,
+                               const boost::shared_ptr<DataSourceReader>& reader,
+                               IValueDisconnector* disconnector /* takes ownership */,
+                               unsigned int windowSize /* number of elements in the sliding window */,
+                               uint64_t windowCapacity /* if 0, memory usage is only controlled by the size of the sliding window */);
+
+    ~DataSourceSequentialReader();
+
+    void Submit(IDataIdentifier* request /* takes ownership */);
+
+    void Start();
+
+    bool HasNext() const;
+
+    Item* Next();
+  };
+}
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -26,7 +26,9 @@
 #include "DicomDataSource.h"
 
 #include "../DicomParsing/ParsedDicomFile.h"
+#include "../Logging.h"
 #include "../OrthancException.h"
+#include "BaseDataIdentifier.h"
 #include "DataSourceReader.h"
 #include "StorageAreaDataSource.h"
 
@@ -35,81 +37,60 @@
 
 namespace Orthanc
 {
-  static size_t ComputeValueSize(size_t size,
-                                 bool isKeepRawBuffer)
-  {
-    if (isKeepRawBuffer)
-    {
-      uint64_t s = 2 * static_cast<uint64_t>(size);
-      if (s != static_cast<uint64_t>(static_cast<size_t>(s)))
-      {
-        return std::numeric_limits<size_t>::max();
-      }
-      else
-      {
-        return static_cast<size_t>(s);
-      }
-    }
-    else
-    {
-      return size;
-    }
-  }
-
-
-  class DicomDataSource::BaseIdentifier : public IDataIdentifier
+  class DicomDataSource::Identifier : public BaseDataIdentifier
   {
   public:
     virtual StorageAreaDataSource::Range* ReadRange(DataSourceReader& reader) const = 0;
 
-    virtual bool IsKeepRawBuffer() const = 0;
+    virtual const FileInfo& GetAttachment() const = 0;
+
+    virtual bool IsUntilPixelData() const = 0;
   };
 
 
-  class DicomDataSource::WholeIdentifier : public DicomDataSource::BaseIdentifier
+  class DicomDataSource::WholeIdentifier : public DicomDataSource::Identifier
   {
   private:
     FileInfo  attachment_;
-    bool      keepRawBuffer_;
-    bool      checkMD5_;
 
   public:
-    explicit WholeIdentifier(const FileInfo& attachment,
-                             bool keepRawBuffer,
-                             bool checkMD5) :
-      attachment_(attachment),
-      keepRawBuffer_(keepRawBuffer),
-      checkMD5_(checkMD5)
+    explicit WholeIdentifier(const FileInfo& attachment) :
+      attachment_(attachment)
     {
     }
 
     virtual bool GetCacheKey(std::string& key) const ORTHANC_OVERRIDE
     {
       key = (attachment_.GetUuid() + "|" +
-             boost::lexical_cast<std::string>(attachment_.GetContentType()) + "|" +
-             boost::lexical_cast<std::string>(keepRawBuffer_));
+             boost::lexical_cast<std::string>(attachment_.GetContentType()));
       return true;
     }
 
     virtual bool EstimateValueSize(size_t& target) const ORTHANC_OVERRIDE
     {
-      target = ComputeValueSize(attachment_.GetUncompressedSize(), keepRawBuffer_);
+      target = attachment_.GetUncompressedSize();
       return true;
     }
 
     virtual StorageAreaDataSource::Range* ReadRange(DataSourceReader& reader) const ORTHANC_OVERRIDE
     {
-      return StorageAreaDataSource::ReadAttachment(reader, attachment_, true /* uncompress */, checkMD5_);
+      return StorageAreaDataSource::Execute(
+        reader, StorageAreaDataSource::CreateAttachmentRequest(attachment_, true /* uncompress */));
     }
 
-    virtual bool IsKeepRawBuffer() const ORTHANC_OVERRIDE
+    virtual const FileInfo& GetAttachment() const ORTHANC_OVERRIDE
     {
-      return keepRawBuffer_;
+      return attachment_;
+    }
+
+    virtual bool IsUntilPixelData() const ORTHANC_OVERRIDE
+    {
+      return false;
     }
   };
 
 
-  class DicomDataSource::BeginningIdentifier : public DicomDataSource::BaseIdentifier
+  class DicomDataSource::BeginningIdentifier : public DicomDataSource::Identifier
   {
   private:
     FileInfo  attachment_;
@@ -141,12 +122,17 @@
 
     virtual StorageAreaDataSource::Range* ReadRange(DataSourceReader& reader) const ORTHANC_OVERRIDE
     {
-      return StorageAreaDataSource::ReadBeginning(reader, attachment_, pixelDataOffset_);
+      return StorageAreaDataSource::Execute(reader, StorageAreaDataSource::CreateBeginningRequest(attachment_, pixelDataOffset_));
     }
 
-    virtual bool IsKeepRawBuffer() const ORTHANC_OVERRIDE
+    virtual const FileInfo& GetAttachment() const ORTHANC_OVERRIDE
     {
-      return false;
+      return attachment_;
+    }
+
+    virtual bool IsUntilPixelData() const ORTHANC_OVERRIDE
+    {
+      return true;
     }
   };
 
@@ -154,17 +140,15 @@
   class DicomDataSource::Value : public IDynamicObject
   {
   private:
-    std::unique_ptr<ParsedDicomFile>   dicom_;
-    size_t                             size_;
-    bool                               hasRawBuffer_;
-    std::string                        rawBuffer_;
+    Mutex                             mutex_;
+    std::unique_ptr<ParsedDicomFile>  dicom_;
+    size_t                            size_;
 
   public:
     Value(ParsedDicomFile* dicom,
           size_t size) :
       dicom_(dicom),
-      size_(size),
-      hasRawBuffer_(false)
+      size_(size)
     {
       if (dicom == NULL)
       {
@@ -172,50 +156,19 @@
       }
     }
 
-    ParsedDicomFile& GetContent() const
-    {
-      return *dicom_;
-    }
-
-    size_t GetRawBufferSize() const
+    size_t GetSize() const
     {
       return size_;
     }
 
-    void SetRawBuffer(const void* data,
-                      size_t size)
+    Mutex::ScopedLock* Lock()
     {
-      if (hasRawBuffer_)
-      {
-        throw OrthancException(ErrorCode_BadSequenceOfCalls);
-      }
-      else if (size != size_)
-      {
-        throw OrthancException(ErrorCode_ParameterOutOfRange);
-      }
-      else
-      {
-        hasRawBuffer_ = true;
-        rawBuffer_.assign(reinterpret_cast<const char*>(data), size);
-      }
+      return new Mutex::ScopedLock(mutex_);
     }
 
-    bool HasRawBuffer() const
-    {
-      return hasRawBuffer_;
-    }
-
-    const void* GetRawBufferData() const
+    ParsedDicomFile& GetContent() const
     {
-      if (hasRawBuffer_)
-      {
-        assert(rawBuffer_.size() == size_);
-        return rawBuffer_.empty() ? NULL : rawBuffer_.c_str();
-      }
-      else
-      {
-        throw OrthancException(ErrorCode_BadSequenceOfCalls);
-      }
+      return *dicom_;
     }
   };
 
@@ -232,7 +185,7 @@
 
   IDynamicObject* DicomDataSource::Load(const IDataIdentifier& obj)
   {
-    const BaseIdentifier& id = dynamic_cast<const BaseIdentifier&>(obj);
+    const Identifier& id = dynamic_cast<const Identifier&>(obj);
 
     std::unique_ptr<StorageAreaDataSource::Range> range(id.ReadRange(*storageAreaReader_));
 
@@ -240,30 +193,19 @@
 
     {
       // Sanity check
-      bool ok = false;
       size_t estimatedSize;
-      if (obj.EstimateValueSize(estimatedSize))
-      {
-        ok = (estimatedSize == ComputeValueSize(size, id.IsKeepRawBuffer()));
-      }
-
-      if (!ok)
+      if (!obj.EstimateValueSize(estimatedSize) ||
+          estimatedSize != size)
       {
         throw OrthancException(ErrorCode_InternalError);
       }
     }
 
+    LOG(INFO) << "Parsing DICOM attachment"
+              << (id.IsUntilPixelData() ? " (until pixel data): " : ": ")
+              << id.GetAttachment().GetUuid();
     std::unique_ptr<Value> value(new Value(new ParsedDicomFile(range->GetData(), size), size));
-
-    if (id.IsKeepRawBuffer())
-    {
-      value->SetRawBuffer(range->GetData(), size);
-      assert(GetValueSize(*value) == 2 * size);
-    }
-    else
-    {
-      assert(GetValueSize(*value) == size);
-    }
+    assert(GetValueSize(*value) == size);
 
     return value.release();
   }
@@ -272,66 +214,77 @@
   size_t DicomDataSource::GetValueSize(const IDynamicObject& obj) const
   {
     const Value& value = dynamic_cast<const Value&>(obj);
-    return ComputeValueSize(value.GetRawBufferSize(), value.HasRawBuffer());
+    return value.GetSize();
   }
 
 
-  DicomDataSource::Dicom::Dicom(const boost::shared_ptr<IDynamicObject>& value) :
-    value_(value)
+  DicomDataSource::Dicom::Dicom(DataSourceAnswer::Item* item) :
+    item_(item)
   {
-    if (value.get() == NULL)
+    if (item == NULL)
     {
       throw OrthancException(ErrorCode_NullPointer);
     }
   }
 
 
-  ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const
+  ParsedDicomFile* DicomDataSource::Dicom::Clone()
   {
-    return dynamic_cast<const Value&>(*that_.value_).GetContent();
+    Lock lock(*this);
+    return lock.GetContent().Clone(true);
   }
 
 
-  bool DicomDataSource::Dicom::Lock::HasRawBuffer() const
+  DicomDataSource::Dicom::Lock::Lock(Dicom& that):
+    that_(that)
   {
-    return dynamic_cast<const Value&>(*that_.value_).HasRawBuffer();
-  }
-
-
-  const void* DicomDataSource::Dicom::Lock::GetRawBufferData() const
-  {
-    return dynamic_cast<const Value&>(*that_.value_).GetRawBufferData();
+    Value& value = dynamic_cast<Value&>(*that_.item_->GetValue());
+    lock_.reset(value.Lock());
   }
 
 
-  size_t DicomDataSource::Dicom::Lock::GetRawBufferSize() const
+  ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const
   {
-    return dynamic_cast<const Value&>(*that_.value_).GetRawBufferSize();
+    const Value& value = dynamic_cast<const Value&>(*that_.item_->GetValue());
+    return value.GetContent();
   }
 
 
-  DicomDataSource::Dicom* DicomDataSource::ReadWhole(DataSourceReader& reader,
-                                                     const FileInfo& attachment,
-                                                     bool keepRawBuffer,
-                                                     bool checkMD5)
+  IDataIdentifier* DicomDataSource::CreateWholeRequest(const FileInfo& attachment)
   {
-    std::unique_ptr<IDataIdentifier> id(new WholeIdentifier(attachment, keepRawBuffer, checkMD5));
-    boost::shared_ptr<IDynamicObject> value = reader.ReadSingle(id.release());
-    return new Dicom(value);
+    return new WholeIdentifier(attachment);
   }
 
 
-  DicomDataSource::Dicom* DicomDataSource::ReadUntilPixelData(DataSourceReader& reader,
-                                                              const FileInfo& attachment,
+  IDataIdentifier* DicomDataSource::CreateUntilPixelDataRequest(const FileInfo& attachment,
                                                               uint64_t pixelDataOffset)
   {
     if (static_cast<uint64_t>(static_cast<size_t>(pixelDataOffset)) != pixelDataOffset)
     {
       throw OrthancException(ErrorCode_NotEnoughMemory);
     }
+    else if (attachment.GetCompressionType() != CompressionType_None)
+    {
+      throw OrthancException(ErrorCode_BadParameterType);
+    }
+    else
+    {
+      return new BeginningIdentifier(attachment, static_cast<size_t>(pixelDataOffset));
+    }
+  }
 
-    std::unique_ptr<IDataIdentifier> id(new BeginningIdentifier(attachment, static_cast<size_t>(pixelDataOffset)));
-    boost::shared_ptr<IDynamicObject> value = reader.ReadSingle(id.release());
-    return new Dicom(value);
+
+  DicomDataSource::Dicom* DicomDataSource::Execute(DataSourceReader& reader,
+                                                   IDataIdentifier* request)
+  {
+    if (request == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingle(request));
+      return new Dicom(item.release());
+    }
   }
 }
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DicomDataSource.h	Tue Jun 02 07:41:56 2026 +0200
@@ -35,6 +35,7 @@
 #include "../Compatibility.h"
 #include "../FileStorage/FileInfo.h"
 #include "../MultiThreading/Mutex.h"
+#include "DataSourceAnswer.h"
 #include "IDataIdentifier.h"
 #include "IDataSource.h"
 
@@ -46,10 +47,10 @@
   class DataSourceReader;
   class ParsedDicomFile;
 
-  class DicomDataSource : public IDataSource
+  class ORTHANC_PUBLIC DicomDataSource : public IDataSource
   {
   private:
-    class BaseIdentifier;
+    class Identifier;
     class WholeIdentifier;
     class BeginningIdentifier;
     class Value;
@@ -63,50 +64,40 @@
 
     virtual size_t GetValueSize(const IDynamicObject& obj) const ORTHANC_OVERRIDE;
 
-    class Dicom : public boost::noncopyable
+    class ORTHANC_PUBLIC Dicom : public boost::noncopyable
     {
     private:
-      Mutex                              mutex_;
-      boost::shared_ptr<IDynamicObject>  value_;
+      std::unique_ptr<DataSourceAnswer::Item>  item_;   // Holding item puts backpressure on the data source
 
     public:
-      explicit Dicom(const boost::shared_ptr<IDynamicObject>& value);
+      explicit Dicom(DataSourceAnswer::Item* item /* takes ownership */);
+
+      ParsedDicomFile* Clone();
 
       /**
        * Access to the DICOM value must be protected by a mutex, as it
        * could be shared by multiple threads if caching is enabled in
        * the DataSourceReader.
        **/
-      class Lock : public boost::noncopyable
+      class ORTHANC_PUBLIC Lock : public boost::noncopyable
       {
       private:
-        Dicom&             that_;
-        Mutex::ScopedLock  lock_;
+        Dicom&                              that_;
+        std::unique_ptr<Mutex::ScopedLock>  lock_;
 
       public:
-        explicit Lock(Dicom& that) :
-          that_(that),
-          lock_(that.mutex_)
-        {
-        }
+        explicit Lock(Dicom& that);
 
         ParsedDicomFile& GetContent() const;
-
-        bool HasRawBuffer() const;
-
-        const void* GetRawBufferData() const;
-
-        size_t GetRawBufferSize() const;
       };
     };
 
-    static Dicom* ReadWhole(DataSourceReader& reader,
-                            const FileInfo& attachment,
-                            bool keepRawBuffer,  // Must be set to "true" for transcoding
-                            bool checkMD5);
+    static IDataIdentifier* CreateWholeRequest(const FileInfo& attachment);
 
-    static Dicom* ReadUntilPixelData(DataSourceReader& reader,
-                                     const FileInfo& attachment,
-                                     uint64_t pixelDataOffset);
+    static IDataIdentifier* CreateUntilPixelDataRequest(const FileInfo& attachment,
+                                                        uint64_t pixelDataOffset);
+
+    static Dicom* Execute(DataSourceReader& reader,
+                          IDataIdentifier* request /* takes ownership */);
   };
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/DicomSequentialReader.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,345 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeaders.h"
+#include "DicomSequentialReader.h"
+
+#include "../DicomParsing/ParsedDicomFile.h"
+#include "../OrthancException.h"
+#include "../StringMemoryBuffer.h"
+#include "BaseDataIdentifier.h"
+#include "DataSourceReader.h"
+#include "DataSourceSequentialReader.h"
+#include "DicomDataSource.h"
+#include "StorageAreaDataSource.h"
+#include "TranscoderDataSource.h"
+
+
+namespace Orthanc
+{
+  DicomSequentialReader::Item::Item(ParsedDicomFile* parsed) :
+    parsed_(parsed)
+  {
+    if (parsed == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+  }
+
+
+  DicomSequentialReader::Item::Item(const boost::shared_ptr<IMemoryBuffer>& raw) :
+    raw_(raw)
+  {
+    if (raw.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+  }
+
+
+  DicomSequentialReader::Item::Item(ParsedDicomFile* parsed /* takes ownership */,
+                                    IMemoryBuffer* raw /* takes ownership */) :
+    parsed_(parsed),
+    raw_(raw)
+  {
+    if (parsed == NULL ||
+        raw == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+  }
+
+
+  ParsedDicomFile& DicomSequentialReader::Item::GetParsedDicomFile()
+  {
+    if (parsed_.get() != NULL)
+    {
+      return *parsed_;
+    }
+    else if (raw_.get() != NULL)
+    {
+      parsed_.reset(new ParsedDicomFile(raw_->GetData(), raw_->GetSize()));
+      return *parsed_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+  }
+
+
+  const IMemoryBuffer& DicomSequentialReader::Item::GetRawMemoryBuffer()
+  {
+    if (raw_.get() != NULL)
+    {
+      return *raw_;
+    }
+    else if (parsed_.get() != NULL)
+    {
+      std::string s;
+      parsed_->SaveToMemoryBuffer(s);
+
+      raw_.reset(StringMemoryBuffer::CreateFromSwap(s));
+      return *raw_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+  }
+
+
+  void DicomSequentialReader::Item::SetUserData(IDynamicObject* userData /* takes ownership */)
+  {
+    if (userData == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      userData_.reset(userData);
+    }
+  }
+
+
+  const IDynamicObject& DicomSequentialReader::Item::GetUserData() const
+  {
+    if (userData_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return *userData_;
+    }
+  }
+
+
+  class DicomSequentialReader::Disconnector : public DataSourceSequentialReader::IValueDisconnector
+  {
+  private:
+    SourceType  sourceType_;
+
+  public:
+    explicit Disconnector(SourceType sourceType) :
+      sourceType_(sourceType)
+    {
+    }
+
+    virtual IDynamicObject* Apply(DataSourceAnswer::Item* source) ORTHANC_OVERRIDE
+    {
+      std::unique_ptr<DataSourceAnswer::Item> protection(source);
+
+      switch (sourceType_)
+      {
+        case SourceType_StorageArea:
+        {
+          std::unique_ptr<StorageAreaDataSource::Range> range(new StorageAreaDataSource::Range(protection.release()));
+          return new Item(range->GetBuffer());  // The buffer is shared through the cache
+        }
+
+        case SourceType_Dicom:
+        {
+          std::unique_ptr<DicomDataSource::Dicom> dicom(new DicomDataSource::Dicom(protection.release()));
+          return new Item(dicom->Clone());
+        }
+
+        case SourceType_Transcoder:
+        {
+          std::unique_ptr<TranscoderDataSource::Transcoded> dicom(new TranscoderDataSource::Transcoded(protection.release()));
+          TranscoderDataSource::Transcoded::LockAsParsed lock(*dicom);
+          return new Item(lock.GetContent().Clone(true));
+        }
+
+        default:
+          throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+  };
+
+
+  DicomSequentialReader::DicomSequentialReader(SourceType sourceType,
+                                               const boost::shared_ptr<IExecutorService>& executor,
+                                               DicomTransferSyntax targetSyntax,
+                                               TranscodingSopInstanceUidMode mode,
+                                               bool hasLossyQuality,
+                                               unsigned int lossyQuality,
+                                               const boost::shared_ptr<DataSourceReader>& reader,
+                                               unsigned int windowSize,
+                                               uint64_t windowCapacity) :
+    sourceType_(sourceType),
+    targetSyntax_(targetSyntax),
+    mode_(mode),
+    hasLossyQuality_(hasLossyQuality),
+    lossyQuality_(lossyQuality),
+    reader_(new DataSourceSequentialReader(executor, reader, new Disconnector(sourceType), windowSize, windowCapacity))
+  {
+  }
+
+
+  void DicomSequentialReader::SubmitInternal(const FileInfo& attachment,
+                                             IDynamicObject* userData)
+  {
+    std::unique_ptr<IDynamicObject> protection(userData);
+
+    std::unique_ptr<IDataIdentifier> id;
+
+    switch (sourceType_)
+    {
+      case SourceType_StorageArea:
+        id.reset(StorageAreaDataSource::CreateAttachmentRequest(attachment, true /* uncompress */));
+        break;
+
+      case SourceType_Dicom:
+        id.reset(DicomDataSource::CreateWholeRequest(attachment));
+        break;
+
+      case SourceType_Transcoder:
+        id.reset(TranscoderDataSource::CreateRequest(attachment, targetSyntax_, mode_, hasLossyQuality_, lossyQuality_));
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_InternalError);
+    }
+
+    if (protection.get() != NULL)
+    {
+      dynamic_cast<BaseDataIdentifier&>(*id).SetUserData(protection.release());
+    }
+
+    reader_->Submit(id.release());
+  }
+
+
+  void DicomSequentialReader::Submit(const FileInfo& attachment)
+  {
+    SubmitInternal(attachment, NULL);
+  }
+
+
+  void DicomSequentialReader::Submit(const FileInfo& attachment,
+                                     IDynamicObject* userData)
+  {
+    if (userData == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+
+    SubmitInternal(attachment, userData);
+  }
+
+
+  void DicomSequentialReader::Start()
+  {
+    reader_->Start();
+  }
+
+
+  bool DicomSequentialReader::HasNext()
+  {
+    return reader_->HasNext();
+  }
+
+
+  DicomSequentialReader::Item* DicomSequentialReader::Next()
+  {
+    std::unique_ptr<DataSourceSequentialReader::Item> source(reader_->Next());
+
+    std::unique_ptr<Item> target(dynamic_cast<Item*>(source->ReleaseValue()));
+
+    if (source->HasUserData())
+    {
+      target->SetUserData(source->ReleaseUserData());
+    }
+
+    return target.release();
+  }
+
+
+  DicomSequentialReader::Factory::Factory(const boost::shared_ptr<IExecutorService>& executor,
+                                          const boost::shared_ptr<DataSourceReader>& storageAreaReader,
+                                          const boost::shared_ptr<DataSourceReader>& dicomReader,
+                                          const boost::shared_ptr<DataSourceReader>& transcoderReader,
+                                          unsigned int windowSize,
+                                          uint64_t windowCapacity) :
+    executor_(executor),
+    storageAreaReader_(storageAreaReader),
+    dicomReader_(dicomReader),
+    transcoderReader_(transcoderReader),
+    windowSize_(windowSize),
+    windowCapacity_(windowCapacity)
+  {
+    if (!executor)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+
+    if (windowSize == 0)
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
+  DicomSequentialReader* DicomSequentialReader::Factory::CreateForOriginalRawMemoryBuffer() const
+  {
+    return new DicomSequentialReader(
+      DicomSequentialReader::SourceType_StorageArea, executor_,
+      DicomTransferSyntax_LittleEndianImplicit, TranscodingSopInstanceUidMode_AllowNew,  /* dummy values */
+      false /* no lossy */, 0 /* unused lossy quality */,
+      storageAreaReader_, windowSize_, windowCapacity_);
+  }
+
+
+  DicomSequentialReader* DicomSequentialReader::Factory::CreateForTranscodedRawMemoryBuffer(DicomTransferSyntax targetSyntax,
+                                                                                            TranscodingSopInstanceUidMode mode,
+                                                                                            bool hasLossyQuality,
+                                                                                            unsigned int lossyQuality) const
+  {
+    // TODO-Streaming : No optimization seems possible, we need to go through the transcoder anyway
+    return CreateForTranscodedParsedDicomFile(targetSyntax, mode, hasLossyQuality, lossyQuality);
+  }
+
+
+  DicomSequentialReader* DicomSequentialReader::Factory::CreateForOriginalParsedDicomFile() const
+  {
+    return new DicomSequentialReader(
+      DicomSequentialReader::SourceType_Dicom, executor_,
+      DicomTransferSyntax_LittleEndianImplicit, TranscodingSopInstanceUidMode_AllowNew,  /* dummy values */
+      false /* no lossy */, 0 /* unused lossy quality */,
+      dicomReader_, windowSize_, windowCapacity_);
+  }
+
+
+  DicomSequentialReader* DicomSequentialReader::Factory::CreateForTranscodedParsedDicomFile(DicomTransferSyntax targetSyntax,
+                                                                                            TranscodingSopInstanceUidMode mode,
+                                                                                            bool hasLossyQuality,
+                                                                                            unsigned int lossyQuality) const
+  {
+    return new DicomSequentialReader(
+      DicomSequentialReader::SourceType_Transcoder, executor_,
+      targetSyntax, mode, hasLossyQuality, lossyQuality,
+      transcoderReader_, windowSize_, windowCapacity_);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/DicomSequentialReader.h	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,159 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "../Compatibility.h"
+#include "../FileStorage/FileInfo.h"
+#include "../IMemoryBuffer.h"
+#include "../MultiThreading/IExecutorService.h"
+
+
+namespace Orthanc
+{
+  class DataSourceReader;
+  class DataSourceSequentialReader;
+  class ParsedDicomFile;
+
+  class ORTHANC_PUBLIC DicomSequentialReader : public boost::noncopyable
+  {
+  public:
+    class ORTHANC_PUBLIC Item : public IDynamicObject
+    {
+    private:
+      std::unique_ptr<ParsedDicomFile>  parsed_;
+      boost::shared_ptr<IMemoryBuffer>  raw_;
+      std::unique_ptr<IDynamicObject>   userData_;
+
+    public:
+      explicit Item(ParsedDicomFile* parsed /* takes ownership */);
+
+      explicit Item(const boost::shared_ptr<IMemoryBuffer>& raw);
+
+      Item(ParsedDicomFile* parsed /* takes ownership */,
+           IMemoryBuffer* raw /* takes ownership */);
+
+      ParsedDicomFile& GetParsedDicomFile();
+
+      // There is a "const" here, as the value could be shared through the cache, so it cannot be modified
+      const IMemoryBuffer& GetRawMemoryBuffer();
+
+      void SetUserData(IDynamicObject* userData /* takes ownership */);
+
+      bool HasUserData() const
+      {
+        return userData_.get() != NULL;
+      }
+
+      const IDynamicObject& GetUserData() const;
+    };
+
+  private:
+    class Disconnector;
+
+    enum SourceType
+    {
+      SourceType_StorageArea,
+      SourceType_Dicom,
+      SourceType_Transcoder
+    };
+
+    SourceType                                     sourceType_;
+    DicomTransferSyntax                            targetSyntax_;
+    TranscodingSopInstanceUidMode                  mode_;
+    bool                                           hasLossyQuality_;
+    unsigned int                                   lossyQuality_;
+    boost::shared_ptr<DataSourceSequentialReader>  reader_;  // boost::shared_ptr<> for PImpl
+
+    DicomSequentialReader(SourceType sourceType,
+                          const boost::shared_ptr<IExecutorService>& executor,
+                          DicomTransferSyntax targetSyntax,
+                          TranscodingSopInstanceUidMode mode,
+                          bool hasLossyQuality,
+                          unsigned int lossyQuality,
+                          const boost::shared_ptr<DataSourceReader>& reader,
+                          unsigned int windowSize,
+                          uint64_t windowCapacity);
+
+    void SubmitInternal(const FileInfo& attachment,
+                        IDynamicObject* userData);
+
+  public:
+    // The factory can be called from multiple threads
+    class ORTHANC_PUBLIC Factory : public boost::noncopyable
+    {
+    private:
+      boost::shared_ptr<IExecutorService>  executor_;
+      boost::shared_ptr<DataSourceReader>  storageAreaReader_;
+      boost::shared_ptr<DataSourceReader>  dicomReader_;
+      boost::shared_ptr<DataSourceReader>  transcoderReader_;
+      unsigned int                         windowSize_;
+      uint64_t                             windowCapacity_;
+
+    public:
+      // The readers are allowed to be NULL, for unit tests
+      Factory(const boost::shared_ptr<IExecutorService>& executor,
+              const boost::shared_ptr<DataSourceReader>& storageAreaReader,
+              const boost::shared_ptr<DataSourceReader>& dicomReader,
+              const boost::shared_ptr<DataSourceReader>& transcoderReader,
+              unsigned int windowSize,
+              uint64_t windowCapacity);
+
+      /**
+       * Methods below prioritize the downloading of the raw DICOM
+       * files (and avoid DICOM parsing if possible).
+       **/
+
+      DicomSequentialReader* CreateForOriginalRawMemoryBuffer() const;
+
+      DicomSequentialReader* CreateForTranscodedRawMemoryBuffer(DicomTransferSyntax targetSyntax,
+                                                                TranscodingSopInstanceUidMode mode,
+                                                                bool hasLossyQuality,
+                                                                unsigned int lossyQuality) const;
+
+      /**
+       * Methods below prioritize the parsing of the DICOM files (and
+       * exploit the DICOM cache if possible).
+       **/
+
+      DicomSequentialReader* CreateForOriginalParsedDicomFile() const;
+
+      DicomSequentialReader* CreateForTranscodedParsedDicomFile(DicomTransferSyntax targetSyntax,
+                                                                TranscodingSopInstanceUidMode mode,
+                                                                bool hasLossyQuality,
+                                                                unsigned int lossyQuality) const;
+    };
+
+    void Submit(const FileInfo& attachment);
+
+    void Submit(const FileInfo& attachment,
+                IDynamicObject* userData /* takes ownership */);
+
+    void Start();
+
+    bool HasNext();
+
+    Item* Next();
+  };
+}
--- a/OrthancFramework/Sources/DataSource/IDataIdentifier.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/IDataIdentifier.h	Tue Jun 02 07:41:56 2026 +0200
@@ -24,7 +24,7 @@
 
 #pragma once
 
-#include "../OrthancFramework.h"
+#include "../IDynamicObject.h"
 
 #include <boost/noncopyable.hpp>
 
@@ -42,5 +42,11 @@
     virtual bool GetCacheKey(std::string& key) const = 0;
 
     virtual bool EstimateValueSize(size_t& target) const = 0;
+
+    virtual bool HasUserData() const = 0;
+
+    virtual const IDynamicObject& GetUserData() const = 0;
+
+    virtual IDynamicObject* ReleaseUserData() = 0;
   };
 }
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -25,9 +25,11 @@
 #include "../PrecompiledHeaders.h"
 #include "StorageAreaDataSource.h"
 
+#include "../MetricsRegistry.h"
 #include "../OrthancException.h"
 #include "../StringMemoryBuffer.h"
 #include "../Toolbox.h"
+#include "BaseDataIdentifier.h"
 #include "DataSourceReader.h"
 
 #if ORTHANC_ENABLE_ZLIB == 1
@@ -37,16 +39,20 @@
 #include <boost/lexical_cast.hpp>
 #include <cassert>
 
+
 namespace Orthanc
 {
   class StorageAreaDataSource::Value : public IDynamicObject
   {
   private:
-    std::unique_ptr<IMemoryBuffer>  buffer_;
+    boost::shared_ptr<IMemoryBuffer>  buffer_;
+    bool                              checkMD5_;
 
   public:
-    explicit Value(IMemoryBuffer* buffer) :
-      buffer_(buffer)
+    explicit Value(IMemoryBuffer* buffer,
+                   bool checkMD5) :
+      buffer_(buffer),
+      checkMD5_(checkMD5)
     {
       if (buffer == NULL)
       {
@@ -54,22 +60,40 @@
       }
     }
 
-    const IMemoryBuffer& GetBuffer() const
+    const boost::shared_ptr<IMemoryBuffer>& GetBuffer() const
     {
       assert(buffer_.get() != NULL);
-      return *buffer_;
+      return buffer_;
+    }
+
+    bool IsCheckMD5() const
+    {
+      return checkMD5_;
     }
   };
 
 
-  class StorageAreaDataSource::Identifier : public IDataIdentifier
+  class StorageAreaDataSource::IPostProcessing : public boost::noncopyable
+  {
+  public:
+    virtual ~IPostProcessing()
+    {
+    }
+
+    // This method can return NULL if no post-processing is required
+    virtual IMemoryBuffer* Apply(const Value& value) const = 0;
+  };
+
+
+  class StorageAreaDataSource::Identifier : public BaseDataIdentifier
   {
   private:
-    std::string      uuid_;
-    FileContentType  type_;
-    uint64_t         start_;
-    uint64_t         end_;
-    std::string      customData_;
+    std::string                       uuid_;
+    FileContentType                   type_;
+    uint64_t                          start_;
+    uint64_t                          end_;
+    std::string                       customData_;
+    std::unique_ptr<IPostProcessing>  postProcessing_;
 
   public:
     Identifier(const std::string& uuid,
@@ -95,9 +119,9 @@
       }
     }
 
-    Value* Read(IPluginStorageArea& area) const
+    IMemoryBuffer* Read(IPluginStorageArea& area) const
     {
-      return new Value(area.ReadRange(uuid_, type_, start_, end_, customData_));
+      return area.ReadRange(uuid_, type_, start_, end_, customData_);
     }
 
     virtual bool GetCacheKey(std::string& key) const ORTHANC_OVERRIDE
@@ -116,155 +140,279 @@
       assert(start_ <= end_);
       return end_ - start_;
     }
+
+    void SetPostProcessing(IPostProcessing* postProcessing)
+    {
+      std::unique_ptr<IPostProcessing> protection(postProcessing);
+
+      if (postProcessing == NULL)
+      {
+        throw OrthancException(ErrorCode_NullPointer);
+      }
+      else if (postProcessing_.get() != NULL)
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
+      else
+      {
+        postProcessing_.reset(protection.release());
+      }
+    }
+
+    bool HasPostProcessing() const
+    {
+      return postProcessing_.get() != NULL;
+    }
+
+    const IPostProcessing& GetPostProcessing() const
+    {
+      if (postProcessing_.get() == NULL)
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
+      else
+      {
+        return *postProcessing_;
+      }
+    }
   };
 
 
+  class StorageAreaDataSource::AttachmentPostProcessing : public StorageAreaDataSource::IPostProcessing
+  {
+  private:
+    FileInfo  attachment_;
+    bool      uncompress_;
+
+  public:
+    AttachmentPostProcessing(const FileInfo& attachment,
+                             bool uncompress) :
+      attachment_(attachment),
+      uncompress_(uncompress)
+    {
+      if (attachment.GetCompressionType() == CompressionType_None)
+      {
+        if (attachment.GetCompressedMD5() != attachment.GetUncompressedMD5() ||
+            attachment.GetCompressedSize() != attachment.GetUncompressedSize())
+        {
+          throw OrthancException(ErrorCode_CorruptedFile);
+        }
+      }
+    }
+
+    const FileInfo& GetAttachment() const
+    {
+      return attachment_;
+    }
+
+    virtual IMemoryBuffer* Apply(const Value& value) const ORTHANC_OVERRIDE
+    {
+      if (value.IsCheckMD5())
+      {
+        std::string md5;
+        Toolbox::ComputeMD5(md5, value.GetBuffer()->GetData(), value.GetBuffer()->GetSize());
+
+        if (md5 != attachment_.GetCompressedMD5())
+        {
+          throw OrthancException(ErrorCode_CorruptedFile);
+        }
+      }
+
+      if (uncompress_)
+      {
+        switch (attachment_.GetCompressionType())
+        {
+          case CompressionType_None:
+            if (value.IsCheckMD5() &&
+                attachment_.GetCompressedMD5() != attachment_.GetUncompressedMD5())
+            {
+              throw OrthancException(ErrorCode_CorruptedFile);
+            }
+            else
+            {
+              return NULL;
+            }
+
+          case CompressionType_ZlibWithSize:
+          {
+#if ORTHANC_ENABLE_ZLIB == 1
+            ZlibCompressor zlib;
+
+            std::string content;
+            zlib.Uncompress(content, value.GetBuffer()->GetData(), value.GetBuffer()->GetSize());
+
+            if (value.IsCheckMD5())
+            {
+              std::string md5;
+              Toolbox::ComputeMD5(md5, content);
+
+              if (md5 != attachment_.GetUncompressedMD5())
+              {
+                throw OrthancException(ErrorCode_CorruptedFile);
+              }
+            }
+
+            return StringMemoryBuffer::CreateFromSwap(content);
+#else
+            throw OrthancException(ErrorCode_InternalError, "Support for zlib is disabled, cannot uncompress attachment");
+#endif
+          }
+
+          default:
+            throw OrthancException(ErrorCode_NotImplemented);
+        }
+      }
+      else
+      {
+        return NULL;
+      }
+    }
+  };
+
+
+  StorageAreaDataSource::StorageAreaDataSource(IPluginStorageArea& area,
+                                               bool checkMD5) :
+    area_(area),
+    checkMD5_(checkMD5)
+  {
+  }
+
+
+  void StorageAreaDataSource::SetMetricsRegistry(const boost::shared_ptr<MetricsRegistry>& metrics,
+                                                 const std::string& metricsReadBytesName,
+                                                 const std::string& metricsReadDurationName)
+  {
+    if (metrics.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      metrics_ = metrics;
+      metricsReadBytesName_ = metricsReadBytesName;
+      metricsReadDurationName_ = metricsReadDurationName;
+
+      metrics_->SetIntegerValue(metricsReadBytesName_, 0);
+      metrics_->SetIntegerValue(metricsReadDurationName_, 0);
+    }
+  }
+
+
   size_t StorageAreaDataSource::GetValueSize(const IDynamicObject& value) const
   {
     const Value& tmp = dynamic_cast<const Value&>(value);
-    return tmp.GetBuffer().GetSize();
+    return tmp.GetBuffer()->GetSize();
   }
 
+
   IDynamicObject* StorageAreaDataSource::Load(const IDataIdentifier& identifier)
   {
     const Identifier& id = dynamic_cast<const Identifier&>(identifier);
-    return id.Read(area_);
+
+    std::unique_ptr<IMemoryBuffer> buffer;
+
+    {
+      std::unique_ptr<MetricsRegistry::Timer> timer;
+      if (metrics_)
+      {
+        timer.reset(new MetricsRegistry::Timer(*metrics_, metricsReadDurationName_));
+      }
+
+      buffer.reset(id.Read(area_));
+    }
+
+    if (metrics_)
+    {
+      metrics_->IncrementIntegerValue(metricsReadBytesName_, static_cast<int64_t>(buffer->GetSize()));
+    }
+
+    return new Value(buffer.release(), checkMD5_);
   }
 
 
-  const StorageAreaDataSource::Value& StorageAreaDataSource::Range::GetValue() const
+  const boost::shared_ptr<IMemoryBuffer>& StorageAreaDataSource::Range::GetBuffer() const
   {
-    assert(value_.get() != NULL);
-    return dynamic_cast<const StorageAreaDataSource::Value&>(*value_);
+    if (item_.get() != NULL)
+    {
+      assert(buffer_.get() == NULL);
+      return dynamic_cast<const Value&>(*item_->GetValue()).GetBuffer();
+    }
+    else if (buffer_.get() != NULL)
+    {
+      assert(item_.get() == NULL);
+      return buffer_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
   }
 
 
-  StorageAreaDataSource::Range::Range(const boost::shared_ptr<IDynamicObject>& value) :
-    value_(value)
+  StorageAreaDataSource::Range::Range(IMemoryBuffer* buffer) :
+    buffer_(buffer)
   {
-    if (value_.get() == NULL)
+    if (buffer == NULL)
     {
       throw OrthancException(ErrorCode_NullPointer);
     }
   }
 
 
-  const void* StorageAreaDataSource::Range::GetData() const
-  {
-    return GetValue().GetBuffer().GetData();
-  }
-
-
-  size_t StorageAreaDataSource::Range::GetSize() const
-  {
-    return GetValue().GetBuffer().GetSize();
-  }
-
-
-  void StorageAreaDataSource::Range::Copy(std::string& to) const
-  {
-    const IMemoryBuffer& buffer = GetValue().GetBuffer();
-    to.assign(reinterpret_cast<const char*>(buffer.GetData()), buffer.GetSize());
-  }
-
-
-  StorageAreaDataSource::Range* StorageAreaDataSource::Range::CreateFromSwap(std::string& content)
+  StorageAreaDataSource::Range::Range(DataSourceAnswer::Item* item) :
+    item_(item)
   {
-    boost::shared_ptr<Value> value(new Value(StringMemoryBuffer::CreateFromSwap(content)));
-    return new Range(value);
-  }
-
-
-  StorageAreaDataSource::Range* StorageAreaDataSource::ReadRange(DataSourceReader& reader,
-                                                                 const std::string& uuid,
-                                                                 FileContentType type,
-                                                                 uint64_t start,
-                                                                 uint64_t end,
-                                                                 const std::string& customData)
-  {
-    std::unique_ptr<IDataIdentifier> id(new Identifier(uuid, type, start, end, customData));
-    boost::shared_ptr<IDynamicObject> value = reader.ReadSingle(id.release());
-    return new Range(value);
-  }
-
-
-  StorageAreaDataSource::Range* StorageAreaDataSource::ReadAttachment(DataSourceReader& reader,
-                                                                      const FileInfo& attachment,
-                                                                      bool uncompress,
-                                                                      bool checkMD5)
-  {
-    if (attachment.GetCompressionType() == CompressionType_None)
+    if (item == NULL)
     {
-      if (attachment.GetCompressedMD5() != attachment.GetUncompressedMD5() ||
-          attachment.GetCompressedSize() != attachment.GetUncompressedSize())
-      {
-        throw OrthancException(ErrorCode_CorruptedFile);
-      }
+      throw OrthancException(ErrorCode_NullPointer);
     }
 
-    std::unique_ptr<StorageAreaDataSource::Range> range(ReadRange(reader,
-                                                                  attachment.GetUuid(),
-                                                                  attachment.GetContentType(),
-                                                                  0, attachment.GetCompressedSize(),
-                                                                  attachment.GetCustomData()));
-
-    if (checkMD5)
-    {
-      std::string md5;
-      Toolbox::ComputeMD5(md5, range->GetData(), range->GetSize());
+    const Identifier& id = dynamic_cast<const Identifier&>(item->GetId());
 
-      if (md5 != attachment.GetCompressedMD5())
-      {
-        throw OrthancException(ErrorCode_CorruptedFile);
-      }
-    }
-
-    if (uncompress)
+    if (id.HasPostProcessing())
     {
-      switch (attachment.GetCompressionType())
-      {
-        case CompressionType_None:
-          return range.release();
+      const Value& value = dynamic_cast<const Value&>(*item->GetValue());
+      std::unique_ptr<IMemoryBuffer> postProcessed(id.GetPostProcessing().Apply(value));
 
-        case CompressionType_ZlibWithSize:
-        {
-#if ORTHANC_ENABLE_ZLIB == 1
-          ZlibCompressor zlib;
-
-          std::string content;
-          zlib.Uncompress(content, range->GetData(), range->GetSize());
-
-          if (checkMD5)
-          {
-            std::string md5;
-            Toolbox::ComputeMD5(md5, content);
-
-            if (md5 != attachment.GetUncompressedMD5())
-            {
-              throw OrthancException(ErrorCode_CorruptedFile);
-            }
-          }
-
-          return Range::CreateFromSwap(content);
-#else
-          throw OrthancException(ErrorCode_InternalError, "Support for zlib is disabled, cannot uncompress attachment");
-#endif
-        }
-
-        default:
-          throw OrthancException(ErrorCode_NotImplemented);
+      if (postProcessed.get() != NULL)
+      {
+        // In this case, the backpressure on the source "item" is released
+        item_.reset(NULL);
+        buffer_.reset(postProcessed.release());
       }
-    }
-    else
-    {
-      return range.release();
+      else
+      {
+        // No postprocessing was applied, keep backpressure on "item"
+      }
     }
   }
 
 
-  StorageAreaDataSource::Range* StorageAreaDataSource::ReadBeginning(DataSourceReader& reader,
-                                                                     const FileInfo& attachment,
-                                                                     uint64_t untilPosition)
+  IDataIdentifier* StorageAreaDataSource::CreateRangeRequest(const std::string& uuid,
+                                                             FileContentType type,
+                                                             uint64_t start,
+                                                             uint64_t end,
+                                                             const std::string& pluginCustomData)
+  {
+    return new Identifier(uuid, type, start, end, pluginCustomData);
+  }
+
+
+  IDataIdentifier* StorageAreaDataSource::CreateAttachmentRequest(const FileInfo& attachment,
+                                                                  bool uncompress)
+  {
+    std::unique_ptr<Identifier> id(new Identifier(attachment.GetUuid(),
+                                                  attachment.GetContentType(),
+                                                  0, attachment.GetCompressedSize(),
+                                                  attachment.GetCustomData()));
+    id->SetPostProcessing(new AttachmentPostProcessing(attachment, uncompress));
+
+    return id.release();
+  }
+
+
+  IDataIdentifier* StorageAreaDataSource::CreateBeginningRequest(const FileInfo& attachment,
+                                                                 uint64_t untilPosition)
   {
     if (attachment.GetCompressionType() != CompressionType_None)
     {
@@ -282,16 +430,15 @@
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
 
-    return ReadRange(reader, attachment.GetUuid(), attachment.GetContentType(),
-                     0, untilPosition, attachment.GetCustomData());
+    return CreateRangeRequest(attachment.GetUuid(), attachment.GetContentType(),
+                              0, untilPosition, attachment.GetCustomData());
   }
 
 
   StorageAreaDataSource::Range* StorageAreaDataSource::ReadRange(DataSourceReader& reader,
                                                                  const FileInfo& attachment,
                                                                  const StorageRange& range,
-                                                                 bool uncompress,
-                                                                 bool checkMD5)
+                                                                 bool uncompress)
   {
     // This mimics "StorageAccessor::ReadRange()"
 
@@ -299,13 +446,13 @@
         attachment.GetCompressionType() != CompressionType_None)
     {
       // An uncompression is needed in this case
-      std::unique_ptr<StorageAreaDataSource::Range> uncompressed(
-        ReadAttachment(reader, attachment, true /* uncompress */, checkMD5));
+      std::unique_ptr<Range> uncompressed(
+        Execute(reader, CreateAttachmentRequest(attachment, true /* uncompress */)));
 
       std::string content;
       range.Extract(content, uncompressed->GetData(), uncompressed->GetSize());
 
-      return Range::CreateFromSwap(content);
+      return new Range(StringMemoryBuffer::CreateFromSwap(content));
     }
     else
     {
@@ -321,9 +468,23 @@
       }
       else
       {
-        return ReadRange(reader, attachment.GetUuid(), attachment.GetContentType(),
-                         start, endExclusive, attachment.GetCustomData());
+        return Execute(reader, CreateRangeRequest(attachment.GetUuid(), attachment.GetContentType(),
+                                                  start, endExclusive, attachment.GetCustomData()));
       }
     }
   }
+
+
+  StorageAreaDataSource::Range* StorageAreaDataSource::Execute(DataSourceReader& reader,
+                                                               IDataIdentifier* request /* takes ownership */)
+  {
+    if (request == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      return new Range(reader.ReadSingle(request));
+    }
+  }
 }
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h	Tue Jun 02 07:41:56 2026 +0200
@@ -32,6 +32,8 @@
 #include "../FileStorage/FileInfo.h"
 #include "../FileStorage/IStorageArea.h"
 #include "../FileStorage/StorageRange.h"
+#include "../IMemoryBuffer.h"
+#include "DataSourceAnswer.h"
 #include "IDataSource.h"
 
 #include <boost/shared_ptr.hpp>
@@ -40,65 +42,82 @@
 namespace Orthanc
 {
   class DataSourceReader;
+  class MetricsRegistry;
 
   class ORTHANC_PUBLIC StorageAreaDataSource : public IDataSource
   {
   private:
     class Value;
     class Identifier;
+    class IPostProcessing;
+    class AttachmentPostProcessing;
 
   private:
-    IPluginStorageArea&  area_;
+    IPluginStorageArea&                 area_;
+    bool                                checkMD5_;
+    boost::shared_ptr<MetricsRegistry>  metrics_;
+    std::string                         metricsReadBytesName_;
+    std::string                         metricsReadDurationName_;
 
   public:
-    explicit StorageAreaDataSource(IPluginStorageArea& area) :
-      area_(area)
-    {
-    }
+    explicit StorageAreaDataSource(IPluginStorageArea& area,
+                                   bool checkMD5);
+
+    void SetMetricsRegistry(const boost::shared_ptr<MetricsRegistry>& metrics,
+                            const std::string& metricsReadBytesName,
+                            const std::string& metricsReadDurationName);
 
     virtual size_t GetValueSize(const IDynamicObject& value) const ORTHANC_OVERRIDE;
 
     virtual IDynamicObject* Load(const IDataIdentifier& identifier) ORTHANC_OVERRIDE;
 
-    class Range : public boost::noncopyable
+    class ORTHANC_PUBLIC Range : public boost::noncopyable
     {
     private:
-      boost::shared_ptr<IDynamicObject>  value_;
-
-      const Value& GetValue() const;
+      std::unique_ptr<DataSourceAnswer::Item>  item_;   // Holding item puts backpressure on the data source (can be NULL)
+      boost::shared_ptr<IMemoryBuffer>         buffer_;  // To be used if "item_ == NULL"
 
     public:
-      explicit Range(const boost::shared_ptr<IDynamicObject>& value);
+      explicit Range(DataSourceAnswer::Item* item /* takes ownership */);
 
-      const void* GetData() const;
+      explicit Range(IMemoryBuffer* buffer /* takes ownership */);
+
+      const boost::shared_ptr<IMemoryBuffer>& GetBuffer() const;
 
-      size_t GetSize() const;
+      const void* GetData() const
+      {
+        return GetBuffer()->GetData();
+      }
 
-      void Copy(std::string& to) const;
+      const size_t GetSize() const
+      {
+        return GetBuffer()->GetSize();
+      }
 
-      static Range* CreateFromSwap(std::string& content);
+      void Copy(std::string& target) const
+      {
+        GetBuffer()->CopyToString(target);
+      }
     };
 
-    static Range* ReadRange(DataSourceReader& reader,
-                            const std::string& uuid,
-                            FileContentType type,
-                            uint64_t start /* inclusive */,
-                            uint64_t end /* exclusive */,
-                            const std::string& customData);
+    static IDataIdentifier* CreateRangeRequest(const std::string& uuid,
+                                               FileContentType type,
+                                               uint64_t start /* inclusive */,
+                                               uint64_t end /* exclusive */,
+                                               const std::string& pluginCustomData);
 
-    static Range* ReadAttachment(DataSourceReader& reader,
-                                 const FileInfo& attachment,
-                                 bool uncompress,
-                                 bool checkMD5);
+    static IDataIdentifier* CreateAttachmentRequest(const FileInfo& attachment,
+                                                    bool uncompress);
 
-    static Range* ReadBeginning(DataSourceReader& reader,
-                                const FileInfo& attachment,
-                                uint64_t untilPosition /* exclusive */);
+    static IDataIdentifier* CreateBeginningRequest(const FileInfo& attachment,
+                                                   uint64_t untilPosition /* exclusive */);
+
+    static Range* Execute(DataSourceReader& reader,
+                          IDataIdentifier* request /* takes ownership */);
 
     static Range* ReadRange(DataSourceReader& reader,
                             const FileInfo& attachment,
                             const StorageRange& range,
-                            bool uncompress,
-                            bool checkMD5);
+                            bool uncompress);
   };
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,343 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../PrecompiledHeaders.h"
+#include "TranscoderDataSource.h"
+
+#include "../DicomParsing/ParsedDicomFile.h"
+#include "../Logging.h"
+#include "../OrthancException.h"
+#include "BaseDataIdentifier.h"
+#include "DataSourceReader.h"
+#include "StorageAreaDataSource.h"
+
+#include <boost/lexical_cast.hpp>
+#include <dcmtk/dcmdata/dcfilefo.h>
+
+
+namespace Orthanc
+{
+  static bool IsLosslessTransferSyntax(DicomTransferSyntax syntax)
+  {
+    return (syntax == DicomTransferSyntax_LittleEndianImplicit ||
+            syntax == DicomTransferSyntax_LittleEndianExplicit ||
+            syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit ||
+            syntax == DicomTransferSyntax_BigEndianExplicit ||
+            syntax == DicomTransferSyntax_JPEGLSLossless ||
+            syntax == DicomTransferSyntax_JPEG2000LosslessOnly ||
+            syntax == DicomTransferSyntax_JPEG2000MulticomponentLosslessOnly ||
+            syntax == DicomTransferSyntax_RLELossless ||
+            syntax == DicomTransferSyntax_JPEGXLLossless ||
+            syntax == DicomTransferSyntax_HighThroughputJPEG2000LosslessOnly);
+  }
+
+
+  class TranscoderDataSource::Value : public IDynamicObject
+  {
+  private:
+    Mutex                             parsedMutex_;
+    std::unique_ptr<ParsedDicomFile>  parsed_;
+    std::unique_ptr<std::string>      raw_;
+    size_t                            size_;
+
+  public:
+    explicit Value(IDicomTranscoder::DicomImage* transcoded)
+    {
+      std::unique_ptr<IDicomTranscoder::DicomImage> protection(transcoded);
+
+      if (transcoded == NULL)
+      {
+        throw OrthancException(ErrorCode_NullPointer);
+      }
+
+      if (!transcoded->HasParsed() &&
+          !transcoded->HasInternalBuffer())
+      {
+        throw OrthancException(ErrorCode_InternalError, "No transcoded image is available");
+      }
+
+      /**
+       * Note that both "transcoded->HasParsed()" and
+       * "transcoded->HasInternalBuffer()" could be true in debug
+       * mode, because of "IDicomTranscoder::CheckTranscoding()".
+       **/
+
+      if (transcoded->HasParsed())
+      {
+        parsed_.reset(transcoded->ReleaseAsParsedDicomFile());
+      }
+
+      if (transcoded->HasInternalBuffer())
+      {
+        raw_.reset(transcoded->ReleaseInternalBuffer());
+        size_ = raw_->size();  // This is more accurate than "f.calcElementLength()" below
+      }
+      else
+      {
+        assert(parsed_.get() != NULL);
+        DcmFileFormat& f = parsed_->GetDcmtkObject();
+        size_ = f.calcElementLength(f.getDataset()->getOriginalXfer(), EET_ExplicitLength);
+      }
+    }
+
+    size_t GetSize() const
+    {
+      return size_;
+    }
+
+    bool HasParsed() const
+    {
+      return parsed_.get() != NULL;
+    }
+
+    bool HasRawBuffer() const
+    {
+      return raw_.get() != NULL;
+    }
+
+    Mutex::ScopedLock* LockParsed()
+    {
+      return new Mutex::ScopedLock(parsedMutex_);
+    }
+
+    ParsedDicomFile& GetParsed() const
+    {
+      if (parsed_.get() == NULL)
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
+      else
+      {
+        return *parsed_;
+      }
+    }
+
+    const std::string& GetRawBuffer() const
+    {
+      if (raw_.get() == NULL)
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
+      else
+      {
+        return *raw_;
+      }
+    }
+  };
+
+
+  class TranscoderDataSource::Identifier : public BaseDataIdentifier
+  {
+  private:
+    FileInfo                       attachment_;
+    DicomTransferSyntax            targetSyntax_;
+    TranscodingSopInstanceUidMode  mode_;
+    bool                           hasLossyQuality_;
+    unsigned int                   lossyQuality_;
+
+  public:
+    Identifier(const FileInfo& attachment,
+               DicomTransferSyntax targetSyntax,
+               TranscodingSopInstanceUidMode mode) :
+      attachment_(attachment),
+      targetSyntax_(targetSyntax),
+      mode_(mode),
+      hasLossyQuality_(false),
+      lossyQuality_(0)
+    {
+    }
+
+    void SetLossyQuality(unsigned int quality)
+    {
+      hasLossyQuality_ = true;
+      lossyQuality_ = quality;
+    }
+
+    virtual bool GetCacheKey(std::string& key) const ORTHANC_OVERRIDE
+    {
+      key = (attachment_.GetUuid() + "|" +
+             GetTransferSyntaxUid(targetSyntax_) + "|" +
+             boost::lexical_cast<std::string>(mode_));
+
+      if (hasLossyQuality_)
+      {
+        key += "|" + boost::lexical_cast<std::string>(lossyQuality_);
+      }
+
+      return true;
+    }
+
+    virtual bool EstimateValueSize(size_t& target) const ORTHANC_OVERRIDE
+    {
+      target = attachment_.GetUncompressedSize();
+      return true;
+    }
+
+    Value* Load(IDicomTranscoder& transcoder,
+                DataSourceReader& storageAreaReader) const
+    {
+      std::unique_ptr<StorageAreaDataSource::Range> range(
+        StorageAreaDataSource::Execute(
+          storageAreaReader, StorageAreaDataSource::CreateAttachmentRequest(attachment_, true /* uncompress */)));
+
+      IDicomTranscoder::DicomImage source;
+      source.SetExternalBuffer(range->GetData(), range->GetSize());
+
+      std::unique_ptr<IDicomTranscoder::DicomImage> target(new IDicomTranscoder::DicomImage);
+
+      std::set<DicomTransferSyntax> allowedSyntaxes;
+      allowedSyntaxes.insert(targetSyntax_);
+
+      LOG(INFO) << "Transcoding DICOM attachment to " << GetTransferSyntaxUid(targetSyntax_) << ": " << attachment_.GetUuid();
+
+      bool success;
+      if (hasLossyQuality_)
+      {
+        success = transcoder.Transcode(*target, source, allowedSyntaxes, mode_, lossyQuality_);
+      }
+      else
+      {
+        success = transcoder.Transcode(*target, source, allowedSyntaxes, mode_);
+      }
+
+      if (success)
+      {
+        return new Value(target.release());
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_NotImplemented);
+      }
+    }
+  };
+
+
+  TranscoderDataSource::TranscoderDataSource(const boost::shared_ptr<IDicomTranscoder>& transcoder,
+                                             const boost::shared_ptr<DataSourceReader>& storageAreaReader) :
+    transcoder_(transcoder),
+    storageAreaReader_(storageAreaReader)
+  {
+    if (!transcoder_ ||
+        !storageAreaReader_)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+  }
+
+
+  IDynamicObject* TranscoderDataSource::Load(const IDataIdentifier& id)
+  {
+    return dynamic_cast<const Identifier&>(id).Load(*transcoder_, *storageAreaReader_);
+  }
+
+
+  size_t TranscoderDataSource::GetValueSize(const IDynamicObject& value) const
+  {
+    return dynamic_cast<const Value&>(value).GetSize();
+  }
+
+
+  TranscoderDataSource::Transcoded::Transcoded(DataSourceAnswer::Item* item) :
+    item_(item)
+  {
+    if (!item)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+  }
+
+
+  TranscoderDataSource::Transcoded::LockAsParsed::LockAsParsed(Transcoded& that)
+  {
+    Value& value = dynamic_cast<Value&>(*that.item_->GetValue());
+
+    if (value.HasParsed())
+    {
+      lock_.reset(value.LockParsed());
+      content_ = &value.GetParsed();
+    }
+    else
+    {
+      assert(value.HasRawBuffer());
+      parsed_.reset(new ParsedDicomFile(value.GetRawBuffer()));
+
+      content_ = parsed_.get();
+    }
+
+    assert(content_ != NULL);
+  }
+
+
+  TranscoderDataSource::Transcoded::LockAsBuffer::LockAsBuffer(Transcoded& that)
+  {
+    Value& value = dynamic_cast<Value&>(*that.item_->GetValue());
+
+    if (value.HasParsed())
+    {
+      std::unique_ptr<Mutex::ScopedLock> lock(value.LockParsed());
+      serialized_.reset(new std::string);
+      value.GetParsed().SaveToMemoryBuffer(*serialized_);
+      content_ = serialized_.get();
+    }
+    else
+    {
+      assert(value.HasRawBuffer());
+      content_ = &value.GetRawBuffer();
+    }
+
+    assert(content_ != NULL);
+  }
+
+
+  IDataIdentifier* TranscoderDataSource::CreateRequest(const FileInfo& attachment,
+                                                       DicomTransferSyntax targetSyntax,
+                                                       TranscodingSopInstanceUidMode mode,
+                                                       bool hasLossyQuality,
+                                                       unsigned int lossyQuality)
+  {
+    std::unique_ptr<Identifier> id(new Identifier(attachment, targetSyntax, mode));
+
+    if (hasLossyQuality &&
+        !IsLosslessTransferSyntax(targetSyntax))
+    {
+      id->SetLossyQuality(lossyQuality);
+    }
+
+    return id.release();
+  }
+
+
+  TranscoderDataSource::Transcoded* TranscoderDataSource::Execute(DataSourceReader& reader,
+                                                                  IDataIdentifier* request)
+  {
+    if (request == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingle(request));
+      return new Transcoded(item.release());
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/DataSource/TranscoderDataSource.h	Tue Jun 02 07:41:56 2026 +0200
@@ -0,0 +1,116 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "../DicomParsing/IDicomTranscoder.h"
+#include "../FileStorage/FileInfo.h"
+#include "../MultiThreading/Mutex.h"
+#include "DataSourceAnswer.h"
+#include "IDataSource.h"
+
+#include <boost/shared_ptr.hpp>
+
+
+namespace Orthanc
+{
+  class DataSourceReader;
+
+  class ORTHANC_PUBLIC TranscoderDataSource : public IDataSource
+  {
+  private:
+    class Value;
+    class Identifier;
+
+    boost::shared_ptr<IDicomTranscoder>  transcoder_;
+    boost::shared_ptr<DataSourceReader>  storageAreaReader_;
+
+  public:
+    TranscoderDataSource(const boost::shared_ptr<IDicomTranscoder>& transcoder,
+                         const boost::shared_ptr<DataSourceReader>& storageAreaReader);
+
+    virtual IDynamicObject* Load(const IDataIdentifier& id) ORTHANC_OVERRIDE;
+
+    virtual size_t GetValueSize(const IDynamicObject& value) const ORTHANC_OVERRIDE;
+
+    class ORTHANC_PUBLIC Transcoded : public boost::noncopyable
+    {
+    private:
+      std::unique_ptr<DataSourceAnswer::Item>  item_;   // Holding item puts backpressure on the data source
+
+    public:
+      explicit Transcoded(DataSourceAnswer::Item* item /* takes ownership */);
+
+      class ORTHANC_PUBLIC LockAsParsed : public boost::noncopyable
+      {
+      private:
+        /**
+         * Access to the transcoded DICOM must be protected by a
+         * mutex, as it could be shared by multiple threads if caching
+         * is enabled in the DataSourceReader.
+         **/
+
+        std::unique_ptr<Mutex::ScopedLock>  lock_;
+        std::unique_ptr<ParsedDicomFile>    parsed_;
+        const ParsedDicomFile*              content_;
+
+      public:
+        explicit LockAsParsed(Transcoded& that);
+
+        const ParsedDicomFile& GetContent() const
+        {
+          return *content_;
+        }
+      };
+
+      class ORTHANC_PUBLIC LockAsBuffer : public boost::noncopyable
+      {
+      private:
+        /**
+         * Access to the transcoded DICOM must only be protected in
+         * the constructor, if serialization to the buffer is required.
+         **/
+
+        std::unique_ptr<std::string>  serialized_;
+        const std::string*            content_;
+
+      public:
+        explicit LockAsBuffer(Transcoded& that);
+
+        const std::string& GetContent() const
+        {
+          return *content_;
+        }
+      };
+    };
+
+    static IDataIdentifier* CreateRequest(const FileInfo& attachment,
+                                          DicomTransferSyntax targetSyntax,
+                                          TranscodingSopInstanceUidMode mode,
+                                          bool hasLossyQuality,
+                                          unsigned int lossyQuality);
+
+    static Transcoded* Execute(DataSourceReader& reader,
+                               IDataIdentifier* request /* takes ownership */);
+  };
+}
--- a/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -426,4 +426,17 @@
       return buffer_->size();
     }
   }
+
+
+  std::string* IDicomTranscoder::DicomImage::ReleaseInternalBuffer()
+  {
+    if (buffer_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      return buffer_.release();
+    }
+  }
 }
--- a/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h	Tue Jun 02 07:41:56 2026 +0200
@@ -24,8 +24,13 @@
 
 #pragma once
 
+#if ORTHANC_ENABLE_DCMTK != 1
+#  error The macro ORTHANC_ENABLE_DCMTK must be set to 1
+#endif
+
 #include "../Compatibility.h"
 #include "../Enumerations.h"
+#include "../IDynamicObject.h"
 
 #include <boost/noncopyable.hpp>
 #include <set>
@@ -43,7 +48,7 @@
   class ORTHANC_PUBLIC IDicomTranscoder : public boost::noncopyable
   {
   public:
-    class ORTHANC_PUBLIC DicomImage : public boost::noncopyable
+    class ORTHANC_PUBLIC DicomImage : public IDynamicObject
     {
     private:
       std::unique_ptr<DcmFileFormat>  parsed_;
@@ -86,6 +91,18 @@
       const void* GetBufferData();
 
       size_t GetBufferSize();
+
+      bool HasParsed() const
+      {
+        return parsed_.get() != NULL;
+      }
+
+      bool HasInternalBuffer() const
+      {
+        return buffer_.get() != NULL;
+      }
+
+      std::string* ReleaseInternalBuffer();
     };
 
 
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomCache.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomCache.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -22,6 +22,10 @@
  **/
 
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "../PrecompiledHeaders.h"
 #include "ParsedDicomCache.h"
 
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomCache.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomCache.h	Tue Jun 02 07:41:56 2026 +0200
@@ -29,7 +29,7 @@
 
 namespace Orthanc
 {
-  class ORTHANC_PUBLIC ParsedDicomCache : public boost::noncopyable
+  class ORTHANC_PUBLIC ORTHANC_DEPRECATED_CLASS(ParsedDicomCache) : public boost::noncopyable
   {
   private:
     class Item;
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -24,7 +24,6 @@
 
 #include "../PrecompiledHeaders.h"
 #include "StorageAccessor.h"
-#include "StorageCache.h"
 
 #include "../Logging.h"
 #include "../StringMemoryBuffer.h"
@@ -47,8 +46,6 @@
 static const std::string METRICS_REMOVE_DURATION = "orthanc_storage_remove_duration_ms";
 static const std::string METRICS_READ_BYTES = "orthanc_storage_read_bytes";
 static const std::string METRICS_WRITTEN_BYTES = "orthanc_storage_written_bytes";
-static const std::string METRICS_CACHE_HIT_COUNT = "orthanc_storage_cache_hit_count";
-static const std::string METRICS_CACHE_MISS_COUNT = "orthanc_storage_cache_miss_count";
 
 
 namespace Orthanc
@@ -72,34 +69,14 @@
 
   StorageAccessor::StorageAccessor(IPluginStorageArea& area) :
     area_(area),
-    cache_(NULL),
     metrics_(NULL)
   {
   }
   
 
   StorageAccessor::StorageAccessor(IPluginStorageArea& area,
-                                   StorageCache& cache) :
-    area_(area),
-    cache_(&cache),
-    metrics_(NULL)
-  {
-  }
-
-
-  StorageAccessor::StorageAccessor(IPluginStorageArea& area,
                                    MetricsRegistry& metrics) :
     area_(area),
-    cache_(NULL),
-    metrics_(&metrics)
-  {
-  }
-
-  StorageAccessor::StorageAccessor(IPluginStorageArea& area,
-                                   StorageCache& cache,
-                                   MetricsRegistry& metrics) :
-    area_(area),
-    cache_(&cache),
     metrics_(&metrics)
   {
   }
@@ -151,12 +128,6 @@
           metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, static_cast<int64_t>(size));
         }
         
-        if (cache_ != NULL)
-        {
-          StorageCache::Accessor cacheAccessor(*cache_);
-          cacheAccessor.Add(uuid, type, data, size);
-        }
-
         info = FileInfo(uuid, type, size, md5);
         info.SetCustomData(customData);
         return;
@@ -194,12 +165,6 @@
           metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, static_cast<int64_t>(compressed.size()));
         }
 
-        if (cache_ != NULL)
-        {
-          StorageCache::Accessor cacheAccessor(*cache_);
-          cacheAccessor.Add(uuid, type, data, size);    // always add uncompressed data to cache
-        }
-
         info = FileInfo(uuid, type, size, md5,
                         CompressionType_ZlibWithSize, compressed.size(), compressedMD5);
         info.SetCustomData(customData);
@@ -211,39 +176,10 @@
     }
   }
 
+
   void StorageAccessor::Read(std::string& content,
                              const FileInfo& info)
   {
-    if (cache_ == NULL)
-    {
-      ReadWholeInternal(content, info);
-    }
-    else
-    {
-      StorageCache::Accessor cacheAccessor(*cache_);
-
-      if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
-      {
-        if (metrics_ != NULL)
-        {
-          metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
-        }
-
-        ReadWholeInternal(content, info);
-
-        // always store the uncompressed data in cache
-        cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
-      } 
-      else if (metrics_ != NULL)
-      {
-        metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
-      }
-    }
-  }
-
-  void StorageAccessor::ReadWholeInternal(std::string& content,
-                                          const FileInfo& info)
-  {
     switch (info.GetCompressionType())
     {
       case CompressionType_None:
@@ -299,35 +235,6 @@
   void StorageAccessor::ReadRaw(std::string& content,
                                 const FileInfo& info)
   {
-    if (cache_ == NULL || info.GetCompressionType() != CompressionType_None)
-    {
-      ReadRawInternal(content, info);
-    }
-    else
-    {// use the cache only if the data is uncompressed.
-      StorageCache::Accessor cacheAccessor(*cache_);
-
-      if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
-      {
-        if (metrics_ != NULL)
-        {
-          metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
-        }
-
-        ReadRawInternal(content, info);
-
-        cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
-      }
-      else if (metrics_ != NULL)
-      {
-        metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
-      }
-    }
-  }
-
-  void StorageAccessor::ReadRawInternal(std::string& content,
-                                        const FileInfo& info)
-  {
     std::unique_ptr<IMemoryBuffer> buffer;
 
     {
@@ -348,11 +255,6 @@
                                FileContentType type,
                                const std::string& customData)
   {
-    if (cache_ != NULL)
-    {
-      cache_->Invalidate(fileUuid, type);
-    }
-
     {
       MetricsTimer timer(*this, METRICS_REMOVE_DURATION);
       area_.Remove(fileUuid, type, customData);
@@ -370,55 +272,6 @@
                                        const FileInfo& info,
                                        uint64_t end /* exclusive */)
   {
-    if (cache_ == NULL)
-    {
-      ReadStartRangeInternal(target, info, end);
-    }
-    else
-    {
-      StorageCache::Accessor accessorStartRange(*cache_);
-      if (!accessorStartRange.FetchStartRange(target, info.GetUuid(), info.GetContentType(), end))
-      {
-        // the start range is not in cache, let's check if the whole file is
-        StorageCache::Accessor accessorWhole(*cache_);
-        if (!accessorWhole.Fetch(target, info.GetUuid(), info.GetContentType()))
-        {
-          if (metrics_ != NULL)
-          {
-            metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
-          }
-
-          // if nothing is in the cache, let's read and cache only the start
-          ReadStartRangeInternal(target, info, end);
-          accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target);
-        }
-        else
-        {
-          if (metrics_ != NULL)
-          {
-            metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
-          }
-
-          // we have read the whole file, check size and resize if needed
-          if (target.size() < end)
-          {
-            throw OrthancException(ErrorCode_CorruptedFile);
-          }
-
-          target.resize(end);
-        }
-      }
-      else if (metrics_ != NULL)
-      {
-        metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
-      }
-    }
-  }
-
-  void StorageAccessor::ReadStartRangeInternal(std::string& target,
-                                                const FileInfo& info,
-                                                uint64_t end /* exclusive */)
-  {
     std::unique_ptr<IMemoryBuffer> buffer;
 
     {
@@ -445,41 +298,14 @@
         info.GetCompressionType() != CompressionType_None)
     {
       // An uncompression is needed in this case
-      if (cache_ != NULL)
-      {
-        StorageCache::Accessor cacheAccessor(*cache_);
-
-        std::string content;
-        if (cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
-        {
-          range.Extract(target, content);
-          return;
-        }
-      }
-
       std::string content;
       Read(content, info);
       range.Extract(target, content);
     }
     else
     {
-      // Access to the raw attachment is sufficient in this case
-      if (info.GetCompressionType() == CompressionType_None &&
-          cache_ != NULL)
-      {
-        // Check out whether the raw attachment is already present in the cache, by chance
-        StorageCache::Accessor cacheAccessor(*cache_);
-
-        std::string content;
-        if (cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
-        {
-          range.Extract(target, content);
-          return;
-        }
-      }
-
       if (range.HasEnd() &&
-        range.GetEndInclusive() >= info.GetCompressedSize())
+          range.GetEndInclusive() >= info.GetCompressedSize())
       {
         throw OrthancException(ErrorCode_BadRange);
       }
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.h	Tue Jun 02 07:41:56 2026 +0200
@@ -55,7 +55,6 @@
 namespace Orthanc
 {
   class MetricsRegistry;
-  class StorageCache;
 
   /**
    * This class handles the compression/decompression of the raw files
@@ -67,9 +66,8 @@
   private:
     class MetricsTimer;
 
-    IPluginStorageArea&     area_;
-    StorageCache*     cache_;
-    MetricsRegistry*  metrics_;
+    IPluginStorageArea&  area_;
+    MetricsRegistry*     metrics_;
 
 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
     void SetupSender(BufferHttpSender& sender,
@@ -81,13 +79,6 @@
     explicit StorageAccessor(IPluginStorageArea& area);
 
     StorageAccessor(IPluginStorageArea& area,
-                    StorageCache& cache);
-
-    StorageAccessor(IPluginStorageArea& area,
-                    MetricsRegistry& metrics);
-
-    StorageAccessor(IPluginStorageArea& area,
-                    StorageCache& cache,
                     MetricsRegistry& metrics);
 
     void Write(FileInfo& info /* out */,
@@ -149,17 +140,5 @@
                     const std::string& mime,
                     const std::string& contentFilename);
 #endif
-
-  private:
-    void ReadStartRangeInternal(std::string& target,
-                                const FileInfo& info,
-                                uint64_t end /* exclusive */);
-
-    void ReadWholeInternal(std::string& content,
-                           const FileInfo& info);
-
-    void ReadRawInternal(std::string& content,
-                         const FileInfo& info);
-
   };
 }
--- a/OrthancFramework/Sources/FileStorage/StorageCache.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,201 +0,0 @@
-/**
- * Orthanc - A Lightweight, RESTful DICOM Store
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- **/
-
-
-#include "../PrecompiledHeaders.h"
-#include "StorageCache.h"
-
-#include "../Compatibility.h"
-#include "../Logging.h"
-#include "../OrthancException.h"
-
-#include <boost/lexical_cast.hpp>
-
-
-namespace Orthanc
-{
-  static std::string GetCacheKeyFullFile(const std::string& uuid,
-                                         FileContentType contentType)
-  {
-    return uuid + ":" + boost::lexical_cast<std::string>(contentType) + ":1";
-  }
-
-
-  static std::string GetCacheKeyStartRange(const std::string& uuid,
-                                           FileContentType contentType)
-  {
-    return uuid + ":" + boost::lexical_cast<std::string>(contentType) + ":0";
-  }
-
-
-  static std::string GetCacheKeyTranscodedInstance(const std::string& uuid,
-                                                   DicomTransferSyntax transferSyntax)
-  {
-    return uuid + ":ts:" + GetTransferSyntaxUid(transferSyntax);
-  }
-
-
-  void StorageCache::SetMaximumSize(size_t size)
-  {
-    cache_.SetMaximumSize(size);
-  }
-  
-
-  void StorageCache::Invalidate(const std::string& uuid,
-                                FileContentType contentType)
-  {
-    std::set<DicomTransferSyntax> transferSyntaxes;
-
-    {
-      boost::mutex::scoped_lock lock(subKeysMutex_);
-      transferSyntaxes = subKeysTransferSyntax_;
-    }
-
-    // invalidate full file, start range file and possible transcoded instances
-    const std::string keyFullFile = GetCacheKeyFullFile(uuid, contentType);
-    cache_.Invalidate(keyFullFile);
-
-    const std::string keyPartialFile = GetCacheKeyStartRange(uuid, contentType);
-    cache_.Invalidate(keyPartialFile);
-    
-    for (std::set<DicomTransferSyntax>::const_iterator it = transferSyntaxes.begin(); it != transferSyntaxes.end(); ++it)
-    {
-      const std::string keyTransferSyntax = GetCacheKeyTranscodedInstance(uuid, *it);
-      cache_.Invalidate(keyTransferSyntax);
-    }
-  }
-
-
-  StorageCache::Accessor::Accessor(StorageCache& cache)
-  : MemoryStringCache::Accessor(cache.cache_),
-    storageCache_(cache)
-  {
-  }
-
-  void StorageCache::Accessor::Add(const std::string& uuid, 
-                                   FileContentType contentType,
-                                   const std::string& value)
-  {
-
-    std::string key = GetCacheKeyFullFile(uuid, contentType);
-    MemoryStringCache::Accessor::Add(key, value);
-  }
-
-  void StorageCache::Accessor::AddStartRange(const std::string& uuid, 
-                                             FileContentType contentType,
-                                             const std::string& value)
-  {
-    const std::string key = GetCacheKeyStartRange(uuid, contentType);
-    MemoryStringCache::Accessor::Add(key, value);
-  }
-
-  void StorageCache::Accessor::Add(const std::string& uuid, 
-                                   FileContentType contentType,
-                                   const void* buffer,
-                                   size_t size)
-  {
-    const std::string key = GetCacheKeyFullFile(uuid, contentType);
-    MemoryStringCache::Accessor::Add(key, reinterpret_cast<const char*>(buffer), size);
-  }                                   
-
-  bool StorageCache::Accessor::Fetch(std::string& value, 
-                                     const std::string& uuid,
-                                     FileContentType contentType)
-  {
-    const std::string key = GetCacheKeyFullFile(uuid, contentType);
-    if (MemoryStringCache::Accessor::Fetch(value, key))
-    {
-      LOG(INFO) << "Read attachment \"" << uuid << "\" with content type "
-                << boost::lexical_cast<std::string>(contentType) << " from cache";
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-  }
-
-  bool StorageCache::Accessor::FetchTranscodedInstance(std::string& value, 
-                                                       const std::string& uuid,
-                                                       DicomTransferSyntax targetSyntax)
-  {
-    const std::string key = GetCacheKeyTranscodedInstance(uuid, targetSyntax);
-    if (MemoryStringCache::Accessor::Fetch(value, key))
-    {
-      LOG(INFO) << "Read instance \"" << uuid << "\" transcoded to "
-                << GetTransferSyntaxUid(targetSyntax) << " from cache";
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-  }
-
-  void StorageCache::Accessor::AddTranscodedInstance(const std::string& uuid,
-                                                     DicomTransferSyntax targetSyntax,
-                                                     const void* buffer,
-                                                     size_t size)
-  {
-    {
-      boost::mutex::scoped_lock lock(storageCache_.subKeysMutex_);
-      storageCache_.subKeysTransferSyntax_.insert(targetSyntax);
-    }
-
-    const std::string key = GetCacheKeyTranscodedInstance(uuid, targetSyntax);
-    MemoryStringCache::Accessor::Add(key, reinterpret_cast<const char*>(buffer), size);
-  }
-
-  bool StorageCache::Accessor::FetchStartRange(std::string& value, 
-                                               const std::string& uuid,
-                                               FileContentType contentType,
-                                               uint64_t end /* exclusive */)
-  {
-    const std::string keyPartialFile = GetCacheKeyStartRange(uuid, contentType);
-    if (MemoryStringCache::Accessor::Fetch(value, keyPartialFile) && value.size() >= end)
-    {
-      if (value.size() > end)  // the start range that has been cached is larger than the requested value
-      {
-        value.resize(end);
-      }
-
-      LOG(INFO) << "Read start of attachment \"" << uuid << "\" with content type "
-                << boost::lexical_cast<std::string>(contentType) << " from cache";
-      return true;
-    }
-
-    return false;
-  }
-
-
-  size_t StorageCache::GetCurrentSize() const
-  {
-    return cache_.GetCurrentSize();
-  }
-  
-  size_t StorageCache::GetNumberOfItems() const
-  {
-    return cache_.GetNumberOfItems();
-  }
-
-}
--- a/OrthancFramework/Sources/FileStorage/StorageCache.h	Mon Jun 01 22:56:23 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-/**
- * Orthanc - A Lightweight, RESTful DICOM Store
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- **/
-
-
-#pragma once
-
-#include "../Cache/MemoryStringCache.h"
-
-#include "../Compatibility.h"  // For ORTHANC_OVERRIDE
-
-#include <boost/thread/mutex.hpp>
-#include <map>
-
-namespace Orthanc
-{
-   /**
-   *  Note: this class is thread safe
-   **/
-   class ORTHANC_PUBLIC StorageCache : public boost::noncopyable
-    {
-    public:
-
-      // The StorageCache is only accessible through this accessor.
-      // It will make sure that only one user will fill load data and fill
-      // the cache if multiple users try to access the same item at the same time.
-      // This scenario happens a lot when multiple workers from a viewer access 
-      // the same file.
-      class Accessor : public MemoryStringCache::Accessor
-      {
-        StorageCache& storageCache_;
-      public:
-        explicit Accessor(StorageCache& cache);
-
-        void Add(const std::string& uuid, 
-                 FileContentType contentType,
-                 const std::string& value);
-
-        void AddStartRange(const std::string& uuid, 
-                           FileContentType contentType,
-                           const std::string& value);
-
-        void Add(const std::string& uuid, 
-                 FileContentType contentType,
-                 const void* buffer,
-                 size_t size);
-
-        bool Fetch(std::string& value, 
-                   const std::string& uuid,
-                   FileContentType contentType);
-
-        bool FetchStartRange(std::string& value, 
-                             const std::string& uuid,
-                             FileContentType contentType,
-                             uint64_t end /* exclusive */);
-
-        bool FetchTranscodedInstance(std::string& value, 
-                                     const std::string& uuid,
-                                     DicomTransferSyntax targetSyntax);
-
-        void AddTranscodedInstance(const std::string& uuid,
-                                   DicomTransferSyntax targetSyntax,
-                                   const void* buffer,
-                                   size_t size);
-      };
-
-    private:
-      MemoryStringCache             cache_;
-      std::set<DicomTransferSyntax> subKeysTransferSyntax_;
-      boost::mutex                  subKeysMutex_;
-
-    public:
-      void SetMaximumSize(size_t size);
-
-      void Invalidate(const std::string& uuid,
-                      FileContentType contentType);
-
-      size_t GetCurrentSize() const;
-      
-      size_t GetNumberOfItems() const;
-
-    private:
-      void Add(const std::string& uuid, 
-               FileContentType contentType,
-               const std::string& value);
-
-      void AddStartRange(const std::string& uuid, 
-                         FileContentType contentType,
-                         const std::string& value);
-
-      void Add(const std::string& uuid, 
-               FileContentType contentType,
-               const void* buffer,
-               size_t size);
-
-      bool Fetch(std::string& value, 
-                 const std::string& uuid,
-                 FileContentType contentType);
-
-      bool FetchStartRange(std::string& value, 
-                           const std::string& uuid,
-                           FileContentType contentType,
-                           uint64_t end /* exclusive */);
-
-    };
-}
--- a/OrthancFramework/Sources/HttpServer/HttpOutput.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/HttpServer/HttpOutput.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -377,7 +377,7 @@
 
 
   void HttpOutput::SendStatus(HttpStatus status,
-                              const char* message,
+                              const void* message,
                               size_t messageSize)
   {
     if (status == HttpStatus_301_MovedPermanently ||
--- a/OrthancFramework/Sources/HttpServer/HttpOutput.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/HttpServer/HttpOutput.h	Tue Jun 02 07:41:56 2026 +0200
@@ -158,7 +158,7 @@
     }
 
     void SendStatus(HttpStatus status,
-		    const char* message,
+		    const void* message,
 		    size_t messageSize);
 
     void SendStatus(HttpStatus status);
--- a/OrthancFramework/Sources/IMemoryBuffer.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/IMemoryBuffer.h	Tue Jun 02 07:41:56 2026 +0200
@@ -40,6 +40,8 @@
     {
     }
 
+    virtual void CopyToString(std::string& target) const = 0;
+
     // The content of the memory buffer will emptied after this call
     virtual void MoveToString(std::string& target) = 0;
 
--- a/OrthancFramework/Sources/MallocMemoryBuffer.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/MallocMemoryBuffer.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -102,6 +102,17 @@
   }
 
     
+  void MallocMemoryBuffer::CopyToString(std::string& target) const
+  {
+    target.resize(size_);
+
+    if (size_ != 0)
+    {
+      memcpy(&target[0], buffer_, size_);
+    }
+  }
+
+
   void MallocMemoryBuffer::MoveToString(std::string& target)
   {
     target.resize(size_);
--- a/OrthancFramework/Sources/MallocMemoryBuffer.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/MallocMemoryBuffer.h	Tue Jun 02 07:41:56 2026 +0200
@@ -53,6 +53,8 @@
                 uint64_t size,
                 FreeFunction freeFunction);
     
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE
--- a/OrthancFramework/Sources/MultiThreading/Mutex.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/MultiThreading/Mutex.h	Tue Jun 02 07:41:56 2026 +0200
@@ -47,6 +47,10 @@
       explicit ScopedLock(Mutex& mutex)
       {
       }
+
+      void Unlock()
+      {
+      }
     };
   };
 
@@ -68,6 +72,11 @@
         lock_(mutex.mutex_)
       {
       }
+
+      void Unlock()
+      {
+        lock_.unlock();
+      }
     };
   };
 #endif
--- a/OrthancFramework/Sources/StringMemoryBuffer.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/StringMemoryBuffer.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -25,9 +25,17 @@
 #include "PrecompiledHeaders.h"
 #include "StringMemoryBuffer.h"
 
+#include "OrthancException.h"
+
 
 namespace Orthanc
 {
+  void StringMemoryBuffer::CopyToString(std::string& target) const
+  {
+    target = buffer_;
+  }
+
+
   void StringMemoryBuffer::MoveToString(std::string& target)
   {
     buffer_.swap(target);
@@ -59,4 +67,21 @@
     result->Copy(buffer, start, end);
     return result.release();
   }
+
+
+  IMemoryBuffer* StringMemoryBuffer::CreateFromBuffer(const void* data,
+                                                      size_t size)
+  {
+    if (size != 0 &&
+        data == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      std::string s;
+      s.assign(reinterpret_cast<const char*>(data), size);
+      return CreateFromSwap(s);
+    }
+  }
 }
--- a/OrthancFramework/Sources/StringMemoryBuffer.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/Sources/StringMemoryBuffer.h	Tue Jun 02 07:41:56 2026 +0200
@@ -50,6 +50,8 @@
       buffer_.swap(buffer);
     }
 
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE
@@ -67,5 +69,8 @@
     static IMemoryBuffer* CreateFromCopy(const std::string& buffer);
 
     static IMemoryBuffer* CreateFromCopy(const std::string& buffer, size_t start /* inclusive */, size_t end /* exclusive */);
+
+    static IMemoryBuffer* CreateFromBuffer(const void* data,
+                                           size_t size);
   };
 }
--- a/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -32,7 +32,6 @@
 #include "../Sources/FileStorage/FilesystemStorage.h"
 #include "../Sources/FileStorage/PluginStorageAreaAdapter.h"
 #include "../Sources/FileStorage/StorageAccessor.h"
-#include "../Sources/FileStorage/StorageCache.h"
 #include "../Sources/Logging.h"
 #include "../Sources/OrthancException.h"
 #include "../Sources/Toolbox.h"
@@ -196,8 +195,7 @@
 TEST(StorageAccessor, NoCompression)
 {
   PluginStorageAreaAdapter s(new FilesystemStorage("UnitTestsStorage"));
-  StorageCache cache;
-  StorageAccessor accessor(s, cache);
+  StorageAccessor accessor(s);
 
   const std::string data = "Hello world";
   FileInfo info;
@@ -219,8 +217,7 @@
 TEST(StorageAccessor, Compression)
 {
   PluginStorageAreaAdapter s(new FilesystemStorage("UnitTestsStorage"));
-  StorageCache cache;
-  StorageAccessor accessor(s, cache);
+  StorageAccessor accessor(s);
 
   const std::string data = "Hello world";
   FileInfo info;
@@ -241,8 +238,7 @@
 TEST(StorageAccessor, Mix)
 {
   PluginStorageAreaAdapter s(new FilesystemStorage("UnitTestsStorage"));
-  StorageCache cache;
-  StorageAccessor accessor(s, cache);
+  StorageAccessor accessor(s);
 
   const std::string compressedData = "Hello";
   const std::string uncompressedData = "HelloWorld";
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -37,6 +37,10 @@
 
 #include <gtest/gtest.h>
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "../Sources/Compatibility.h"
 #include "../Sources/DicomFormat/DicomImageInformation.h"
 #include "../Sources/DicomFormat/DicomPath.h"
--- a/OrthancFramework/UnitTestsSources/MemoryCacheTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/MemoryCacheTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -29,6 +29,10 @@
 
 #include <gtest/gtest.h>
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "../Sources/Cache/MemoryCache.h"
 #include "../Sources/Cache/MemoryStringCache.h"
 #include "../Sources/Cache/SharedArchive.h"
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -491,11 +491,4 @@
   ASSERT_EQ(MEGABYTE * static_cast<int16_t>(16 * 1024), 16ull * 1024ull * 1024ull * 1024ull);
   ASSERT_EQ(static_cast<int32_t>(16 * 1024 * 1024) * KILOBYTE, 16ull * 1024ull * 1024ull * 1024ull);
   ASSERT_EQ(KILOBYTE * static_cast<int32_t>(16 * 1024 * 1024), 16ull * 1024ull * 1024ull * 1024ull);
-
-  ASSERT_EQ(8, sizeof(static_cast<int16_t>(16) * GIGABYTE));
-  ASSERT_EQ(8, sizeof(GIGABYTE * static_cast<int16_t>(16)));
-  ASSERT_EQ(8, sizeof(static_cast<int16_t>(16 * 1024) * MEGABYTE));
-  ASSERT_EQ(8, sizeof(MEGABYTE * static_cast<int16_t>(16 * 1024)));
-  ASSERT_EQ(8, sizeof(static_cast<int32_t>(16 * 1024 * 1024) * KILOBYTE));
-  ASSERT_EQ(8, sizeof(KILOBYTE * static_cast<int32_t>(16 * 1024 * 1024)));
 }
--- a/OrthancServer/CMakeLists.txt	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/CMakeLists.txt	Tue Jun 02 07:41:56 2026 +0200
@@ -163,7 +163,6 @@
   ${CMAKE_SOURCE_DIR}/Sources/ServerJobs/SplitStudyJob.cpp
   ${CMAKE_SOURCE_DIR}/Sources/ServerJobs/StorageCommitmentScpJob.cpp
   ${CMAKE_SOURCE_DIR}/Sources/ServerJobs/StoreJob.cpp
-  ${CMAKE_SOURCE_DIR}/Sources/ServerJobs/ThreadedInstancesLoader.cpp
   ${CMAKE_SOURCE_DIR}/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp  
   ${CMAKE_SOURCE_DIR}/Sources/ServerToolbox.cpp
   ${CMAKE_SOURCE_DIR}/Sources/ServerTranscoder.cpp
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -35,6 +35,8 @@
 
 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h"
 #include "../../../OrthancFramework/Sources/Compression/ZlibCompressor.h"
+#include "../../../OrthancFramework/Sources/DataSource/DicomDataSource.h"
+#include "../../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h"
 #include "../../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
 #include "../../../OrthancFramework/Sources/DicomNetworking/DicomConnectionInfo.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h"
@@ -65,6 +67,7 @@
 #include "../../Sources/Search/HierarchicalMatcher.h"
 #include "../../Sources/ServerContext.h"
 #include "../../Sources/ServerToolbox.h"
+#include "../../Sources/ServerTranscoder.h"
 #include "OrthancPluginDatabase.h"
 #include "OrthancPluginDatabaseV3.h"
 #include "OrthancPluginDatabaseV4.h"
@@ -3542,14 +3545,14 @@
     const _OrthancPluginGetDicomForInstance& p = 
       *reinterpret_cast<const _OrthancPluginGetDicomForInstance*>(parameters);
 
-    std::string dicom;
+    std::unique_ptr<StorageAreaDataSource::Range> raw;
 
     {
       PImpl::ServerContextReference lock(*pimpl_);
-      lock.GetContext().ReadDicom(dicom, p.instanceId);
-    }
-
-    CopyToMemoryBuffer(p.target, dicom);
+      raw.reset(lock.GetContext().ReadRawDicom(p.instanceId));
+    }
+
+    CopyToMemoryBuffer(p.target, raw->GetData(), raw->GetSize());
   }
 
   static void ThrowOnHttpError(HttpStatus httpStatus)
@@ -4036,7 +4039,7 @@
         std::unique_ptr<ImageAccessor> decoded;
         {
           PImpl::ServerContextReference lock(*pimpl_);
-          decoded.reset(lock.GetContext().DecodeDicomFrame(instance, p.frameIndex));
+          decoded.reset(lock.GetContext().GetTranscoder()->DecodeFrame(instance, p.frameIndex));
         }
         
         *(p.targetImage) = ReturnImage(decoded);
@@ -4150,8 +4153,14 @@
 
       case OrthancPluginImageFormat_Dicom:
       {
-        PImpl::ServerContextReference lock(*pimpl_);
-        image.reset(lock.GetContext().DecodeDicomFrame(p.data, p.size, 0));
+        std::unique_ptr<DicomInstanceToStore> instance(DicomInstanceToStore::CreateFromBuffer(p.data, p.size));
+
+        {
+          PImpl::ServerContextReference lock(*pimpl_);
+          image.reset(lock.GetContext().GetTranscoder()->DecodeFrame(
+                        *instance, 0 /* frame index is not available in _OrthancPluginUncompressImage */));
+        }
+
         break;
       }
 
@@ -4696,14 +4705,11 @@
         throw OrthancException(ErrorCode_NullPointer);
       }
 
-      std::string content;
-
       {
         PImpl::ServerContextReference lock(*pimpl_);
-        lock.GetContext().ReadDicom(content, p.instanceId);
-      }
-
-      dicom.reset(new ParsedDicomFile(content));
+        std::unique_ptr<DicomDataSource::Dicom> loaded(lock.GetContext().ReadParsedDicom(p.instanceId));
+        dicom.reset(loaded->Clone());
+      }
     }
 
     Json::Value json;
@@ -4828,8 +4834,13 @@
 
       case _OrthancPluginService_DecodeDicomImage:
       {
-        PImpl::ServerContextReference lock(*pimpl_);
-        result.reset(lock.GetContext().DecodeDicomFrame(p.constBuffer, p.bufferSize, p.frameIndex));
+        std::unique_ptr<DicomInstanceToStore> instance(DicomInstanceToStore::CreateFromBuffer(p.constBuffer, p.bufferSize));
+
+        {
+          PImpl::ServerContextReference lock(*pimpl_);
+          result.reset(lock.GetContext().GetTranscoder()->DecodeFrame(*instance, p.frameIndex));
+        }
+
         break;
       }
 
@@ -5124,14 +5135,14 @@
     {
       case OrthancPluginLoadDicomInstanceMode_WholeDicom:
       {
-        std::string buffer;
+        std::unique_ptr<StorageAreaDataSource::Range> raw;
 
         {
           PImpl::ServerContextReference lock(*pimpl_);
-          lock.GetContext().ReadDicom(buffer, params.instanceId);
-        }
-
-        target.reset(new DicomInstanceFromBuffer(buffer));
+          raw.reset(lock.GetContext().ReadRawDicom(params.instanceId));
+        }
+
+        target.reset(new DicomInstanceFromBuffer(raw->GetData(), raw->GetSize()));
         break;
       }
         
@@ -5141,17 +5152,9 @@
         std::unique_ptr<ParsedDicomFile> parsed;
 
         {
-          std::string buffer;
-        
-          {
-            PImpl::ServerContextReference lock(*pimpl_);
-            if (!lock.GetContext().ReadDicomUntilPixelData(buffer, params.instanceId))
-            {
-              lock.GetContext().ReadDicom(buffer, params.instanceId);
-            }
-          }
-
-          parsed.reset(new ParsedDicomFile(buffer));
+          PImpl::ServerContextReference lock(*pimpl_);
+          std::unique_ptr<DicomDataSource::Dicom> loaded(lock.GetContext().ReadParsedDicom(params.instanceId));
+          parsed.reset(loaded->Clone());
         }
 
         parsed->RemoveFromPixelData();
@@ -6081,7 +6084,7 @@
 
           {
             PImpl::ServerContextReference lock(*pimpl_);
-            success = lock.GetContext().GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew);
+            success = lock.GetContext().GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew);
           }
 
           if (success)
@@ -6889,7 +6892,7 @@
 
   ImageAccessor* OrthancPlugins::Decode(const void* dicom,
                                         size_t size,
-                                        unsigned int frame)
+                                        unsigned int frame) const
   {
     boost::shared_lock<boost::shared_mutex> lock(pimpl_->decoderTranscoderMutex_);
 
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.h	Tue Jun 02 07:41:56 2026 +0200
@@ -53,7 +53,6 @@
 #include "../../../OrthancFramework/Sources/JobsEngine/IJob.h"
 #include "../../../OrthancFramework/Sources/MallocMemoryBuffer.h"
 #include "../../Sources/Database/IDatabaseWrapper.h"
-#include "../../Sources/IDicomImageDecoder.h"
 #include "../../Sources/IServerListener.h"
 #include "../../Sources/ServerJobs/IStorageCommitmentFactory.h"
 #include "PluginMemoryBuffer64.h"
@@ -73,7 +72,6 @@
     public IPluginServiceProvider, 
     public IServerListener,
     public IWorklistRequestHandlerFactory,
-    public IDicomImageDecoder,
     public IFindRequestHandlerFactory,
     public IMoveRequestHandlerFactory,
     public IStorageCommitmentFactory,
@@ -394,9 +392,9 @@
 
     bool HasCustomTranscoder();
 
-    virtual ImageAccessor* Decode(const void* dicom,
-                                  size_t size,
-                                  unsigned int frame) ORTHANC_OVERRIDE;
+    ImageAccessor* Decode(const void* dicom,
+                          size_t size,
+                          unsigned int frame) const;
 
     bool IsAllowed(HttpMethod method,
                    const char* uri,
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -61,6 +61,19 @@
   }
 
 
+  void PluginMemoryBuffer32::CopyToString(std::string& target) const
+  {
+    SanityCheck();
+
+    target.resize(buffer_.size);
+
+    if (buffer_.size != 0)
+    {
+      memcpy(&target[0], buffer_.data, buffer_.size);
+    }
+  }
+
+
   void PluginMemoryBuffer32::MoveToString(std::string& target)
   {
     SanityCheck();
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h	Tue Jun 02 07:41:56 2026 +0200
@@ -49,6 +49,8 @@
       Clear();
     }
 
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE;
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -58,6 +58,19 @@
   }
 
 
+  void PluginMemoryBuffer64::CopyToString(std::string& target) const
+  {
+    SanityCheck();
+
+    target.resize(buffer_.size);
+
+    if (buffer_.size != 0)
+    {
+      memcpy(&target[0], buffer_.data, buffer_.size);
+    }
+  }
+
+
   void PluginMemoryBuffer64::MoveToString(std::string& target)
   {
     SanityCheck();
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h	Tue Jun 02 07:41:56 2026 +0200
@@ -49,6 +49,8 @@
       Clear();
     }
 
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE;
--- a/OrthancServer/Resources/ImplementationNotes/JobsEngineClasses.txt	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Resources/ImplementationNotes/JobsEngineClasses.txt	Tue Jun 02 07:41:56 2026 +0200
@@ -22,6 +22,6 @@
     virtual bool HandleTrailingStep() = 0;
 
 
-class StoreJob : SetOfInstancesJob   (contains a ThreadedInstancesLoader)
+class StoreJob : SetOfInstancesJob   (contains a DicomSequentialReader)
 
-Class ModalityStoreJob : StoreJob
\ No newline at end of file
+Class ModalityStoreJob : StoreJob
--- a/OrthancServer/Resources/RunCppCheck-2.1.sh	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Resources/RunCppCheck-2.1.sh	Tue Jun 02 07:41:56 2026 +0200
@@ -15,8 +15,8 @@
 assertWithSideEffect:../../OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp:279
 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:292
 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:391
-assertWithSideEffect:../../OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp:3078
-assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:287
+assertWithSideEffect:../../OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp:3110
+assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:293
 constParameter:../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp
 knownArgument:../../OrthancFramework/UnitTestsSources/ImageTests.cpp
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp
@@ -26,18 +26,18 @@
 stlFindInsert:../../OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp:74
 stlFindInsert:../../OrthancServer/Sources/Database/MainDicomTagsRegistry.cpp:65
 stlFindInsert:../../OrthancServer/Sources/Database/ResourcesContent.h:141
-stlFindInsert:../../OrthancServer/Sources/OrthancWebDav.cpp:329
+stlFindInsert:../../OrthancServer/Sources/OrthancWebDav.cpp:333
 stlFindInsert:../../OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp:42
-stlFindInsert:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:362
+stlFindInsert:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:368
 stlFindInsert:../../OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp:192
 syntaxError:../../OrthancFramework/Sources/SQLite/FunctionContext.h:53
 syntaxError:../../OrthancFramework/UnitTestsSources/DicomMapTests.cpp:74
 syntaxError:../../OrthancServer/UnitTestsSources/UnitTestsMain.cpp:325
 unreadVariable:../../OrthancFramework/Sources/FileStorage/StorageAccessor.cpp
-unreadVariable:../../OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp:1173
-useInitializationList:../../OrthancFramework/Sources/Images/PngReader.cpp:92
+unreadVariable:../../OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp:1174
+useInitializationList:../../OrthancFramework/Sources/Images/PngReader.cpp:100
 useInitializationList:../../OrthancFramework/Sources/Images/PngWriter.cpp:99
-useInitializationList:../../OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp:275
+useInitializationList:../../OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp:277
 EOF
 
 CPPCHECK_BUILD_DIR=/tmp/cppcheck-build-dir-2.1/
--- a/OrthancServer/Resources/RunCppCheck-2.17.1.sh	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Resources/RunCppCheck-2.17.1.sh	Tue Jun 02 07:41:56 2026 +0200
@@ -12,24 +12,20 @@
 cat <<EOF > /tmp/cppcheck-suppressions.txt
 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:292
 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:391
-assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:287
+assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:293
 constParameterCallback:../../OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp:50
 constParameterCallback:../../OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp:112
 constParameterCallback:../../OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp:113
 constParameterCallback:../../OrthancFramework/Sources/Pkcs11.cpp:125
 constParameterCallback:../../OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp:3553
-constParameterCallback:../../OrthancServer/Sources/OrthancGetRequestHandler.cpp:48
+constParameterCallback:../../OrthancServer/Sources/OrthancGetRequestHandler.cpp:66
 constParameterPointer:../../OrthancFramework/Sources/Logging.cpp:450
 constParameterPointer:../../OrthancFramework/Sources/Logging.cpp:454
 constParameterPointer:../../OrthancFramework/Sources/Toolbox.cpp:3351
 knownConditionTrueFalse:../../OrthancFramework/Sources/DicomNetworking/Internals/CommandDispatcher.cpp:112
-knownConditionTrueFalse:../../OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp:440
-knownConditionTrueFalse:../../OrthancFramework/Sources/Images/PamReader.cpp:204
-knownConditionTrueFalse:../../OrthancFramework/Sources/Images/PamReader.cpp:207
+knownConditionTrueFalse:../../OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp:441
+knownConditionTrueFalse:../../OrthancFramework/Sources/Images/PamReader.cpp:208
 knownConditionTrueFalse:../../OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp:345
-knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2444
-knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2445
-knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2446
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2447
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2448
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2449
@@ -37,6 +33,9 @@
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2451
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2452
 knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2453
+knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2454
+knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2455
+knownConditionTrueFalse:../../OrthancServer/Plugins/Engine/OrthancPlugins.cpp:2456
 nullPointer:../../OrthancFramework/UnitTestsSources/RestApiTests.cpp:321
 stlFindInsert:../../OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp:166
 stlFindInsert:../../OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp:74
@@ -45,11 +44,11 @@
 syntaxError:../../OrthancFramework/UnitTestsSources/DicomMapTests.cpp:74
 syntaxError:../../OrthancFramework/UnitTestsSources/ZipTests.cpp:133
 syntaxError:../../OrthancServer/UnitTestsSources/UnitTestsMain.cpp:325
-useInitializationList:../../OrthancFramework/Sources/Images/PngReader.cpp:99
+useInitializationList:../../OrthancFramework/Sources/Images/PngReader.cpp:100
 useInitializationList:../../OrthancFramework/Sources/Images/PngWriter.cpp:99
-useInitializationList:../../OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp:280
+useInitializationList:../../OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp:277
 variableScope:../../OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp:230
-variableScope:../../OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp:97
+variableScope:../../OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp:98
 EOF
 
 CPPCHECK_BUILD_DIR=/tmp/cppcheck-build-dir-2.17.1/
--- a/OrthancServer/Resources/RunCppCheck-2.20.0.sh	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Resources/RunCppCheck-2.20.0.sh	Tue Jun 02 07:41:56 2026 +0200
@@ -10,10 +10,10 @@
 fi
 
 cat <<EOF > /tmp/cppcheck-suppressions.txt
-assertWithSideEffect:../../OrthancFramework/Sources/DataSource/DataSourceReader.cpp:220
+assertWithSideEffect:../../OrthancFramework/Sources/DataSource/DataSourceReader.cpp:310
 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:292
 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:391
-assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:287
+assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:293
 constParameterPointer:../../OrthancFramework/Sources/Logging.cpp:450
 constParameterPointer:../../OrthancFramework/Sources/Logging.cpp:454
 constParameterPointer:../../OrthancFramework/Sources/Toolbox.cpp:3351
@@ -25,11 +25,11 @@
 syntaxError:../../OrthancFramework/Sources/SQLite/FunctionContext.h
 syntaxError:../../OrthancFramework/UnitTestsSources/DicomMapTests.cpp:74
 syntaxError:../../OrthancServer/UnitTestsSources/UnitTestsMain.cpp:325
-useInitializationList:../../OrthancFramework/Sources/Images/PngReader.cpp:99
+useInitializationList:../../OrthancFramework/Sources/Images/PngReader.cpp:100
 useInitializationList:../../OrthancFramework/Sources/Images/PngWriter.cpp:99
-useInitializationList:../../OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp:280
+useInitializationList:../../OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp:277
 variableScope:../../OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp:230
-variableScope:../../OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp:97
+variableScope:../../OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp:98
 EOF
 
 CPPCHECK_BUILD_DIR=/tmp/cppcheck-build-dir-2.20.0/
--- a/OrthancServer/Sources/IDicomImageDecoder.h	Mon Jun 01 22:56:23 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/**
- * Orthanc - A Lightweight, RESTful DICOM Store
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-
-#pragma once
-
-#include "../../OrthancFramework/Sources/Images/ImageAccessor.h"
-
-#include <boost/noncopyable.hpp>
-
-namespace Orthanc
-{
-  class IDicomImageDecoder : public boost::noncopyable
-  {
-  public:
-    virtual ~IDicomImageDecoder()
-    {
-    }
-
-    virtual ImageAccessor* Decode(const void* dicom,
-                                  size_t size,
-                                  unsigned int frame) = 0;
-  };
-}
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -30,7 +30,7 @@
 #include "OrthancConfiguration.h"
 #include "ServerContext.h"
 #include "ServerJobs/DicomModalityStoreJob.h"
-#include "ServerJobs/ThreadedInstancesLoader.h"
+#include "ServerTranscoder.h"
 
 #include <dcmtk/dcmdata/dcdeftag.h>
 #include <dcmtk/dcmdata/dcfilefo.h>
@@ -44,6 +44,24 @@
 
 namespace Orthanc
 {
+  class OrthancGetRequestHandler::ReaderUserData : public IDynamicObject
+  {
+  private:
+    std::string instanceId_;
+
+  public:
+    explicit ReaderUserData(const std::string& instanceId) :
+      instanceId_(instanceId)
+    {
+    }
+
+    const std::string& GetInstanceId() const
+    {
+      return instanceId_;
+    }
+  };
+
+
   static void ProgressCallback(void *callbackData,
                                T_DIMSE_StoreProgress *progress,
                                T_DIMSE_C_StoreRQ *req)
@@ -65,45 +83,55 @@
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
     
-    if (instancesLoader_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-
-    const std::string& id = instancesIds_[position_++];
-
-    std::string dicom;
-    instancesLoader_->WaitDicomInstance(dicom, id);
-    
-    if (dicom.empty())
-    {
-      throw OrthancException(ErrorCode_BadFileFormat);
-    }
-
-    std::unique_ptr<DcmFileFormat> parsed(
-      FromDcmtkBridge::LoadFromMemoryBuffer(dicom.c_str(), dicom.size()));
-
-    if (parsed.get() == NULL ||
-        parsed->getDataset() == NULL)
+    if (instancesLoader_.get() == NULL ||
+        !instancesLoader_->HasNext())
     {
       throw OrthancException(ErrorCode_InternalError);
     }
-    
-    DcmDataset& dataset = *parsed->getDataset();
-    
-    OFString a, b;
-    if (!dataset.findAndGetOFString(DCM_SOPClassUID, a).good() ||
-        !dataset.findAndGetOFString(DCM_SOPInstanceUID, b).good())
+
     {
-      throw OrthancException(ErrorCode_NoSopClassOrInstance,
-                             "Unable to determine the SOP class/instance for C-STORE with AET " +
-                             originatorAet_);
-    }
+      /**
+       * It is OK to modify the content of "dicom", as
+       * "DicomSequentialReader" returns copies of the cached objects
+       * (cf. "DataSourceSequentialReader::IValueDisconnector"). (*)
+       **/
+      std::unique_ptr<DicomSequentialReader::Item> next(instancesLoader_->Next());
+      assert(next.get() != NULL &&
+             next->HasUserData());
+
+      {
+        const std::string& expectedId = instancesIds_[position_];
+        position_++;
+
+        // This is just a sanity check, the class "ReaderUserData" could be removed
+        const ReaderUserData& userData = dynamic_cast<const ReaderUserData&>(next->GetUserData());
+        if (userData.GetInstanceId() != expectedId)
+        {
+          throw OrthancException(ErrorCode_InternalError);
+        }
+      }
 
-    std::string sopClassUid(a.c_str());
-    std::string sopInstanceUid(b.c_str());
+      ParsedDicomFile& dicom = next->GetParsedDicomFile();
+
+      if (dicom.GetDcmtkObject().getDataset() == NULL)
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
     
-    return PerformGetSubOp(assoc, sopClassUid, sopInstanceUid, parsed.release());
+      OFString a, b;
+      if (!dicom.GetDcmtkObject().getDataset()->findAndGetOFString(DCM_SOPClassUID, a).good() ||
+          !dicom.GetDcmtkObject().getDataset()->findAndGetOFString(DCM_SOPInstanceUID, b).good())
+      {
+        throw OrthancException(ErrorCode_NoSopClassOrInstance,
+                               "Unable to determine the SOP class/instance for C-STORE with AET " +
+                               originatorAet_);
+      }
+
+      std::string sopClassUid(a.c_str());
+      std::string sopInstanceUid(b.c_str());
+
+      return PerformGetSubOp(assoc, sopClassUid, sopInstanceUid, dicom);
+    }
   }
 
   
@@ -233,13 +261,10 @@
   bool OrthancGetRequestHandler::PerformGetSubOp(T_ASC_Association* assoc,
                                                  const std::string& sopClassUid,
                                                  const std::string& sopInstanceUid,
-                                                 DcmFileFormat* dicomRaw)
+                                                 ParsedDicomFile& dicom)
   {
-    assert(dicomRaw != NULL);
-    std::unique_ptr<DcmFileFormat> dicom(dicomRaw);
-    
     DicomTransferSyntax sourceSyntax;
-    if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, *dicom))
+    if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom.GetDcmtkObject()))
     {
       failedCount_++;
       AddFailedUIDInstance(sopInstanceUid);
@@ -316,7 +341,7 @@
       // No transcoding is required
       DcmDataset *stDetailTmp = NULL;
       cond = DIMSE_storeUser(
-        assoc, presId, &req, NULL /* imageFileName */, dicom->getDataset(),
+        assoc, presId, &req, NULL /* imageFileName */, dicom.GetDcmtkObject().getDataset(),
         ProgressCallback, NULL /* callbackData */,
         (timeout_ > 0 ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), static_cast<int>(timeout_),
         &rsp, &stDetailTmp, &cancelParameters);
@@ -326,12 +351,19 @@
     {
       // Transcoding to the selected uncompressed transfer syntax
       IDicomTranscoder::DicomImage source, transcoded;
-      source.AcquireParsed(dicom.release());
+      source.AcquireParsed(dicom);  // This invalidates the "dicom" object, cf. (*)
+
+      /**
+       * TODO-Streaming : It doesn't seem possible to uniformly trancode upfront
+       * using "DicomSequentialReader::CreateForTranscoded()", as the
+       * selected transfer syntax is not constant, but varies upon
+       * each individual instance given the presentation context.
+       **/
 
       std::set<DicomTransferSyntax> ts;
       ts.insert(selectedSyntax);
       
-      if (context_.GetTranscoder().Transcode(transcoded, source, ts, TranscodingSopInstanceUidMode_AllowNew))
+      if (context_.GetTranscoder()->Transcode(transcoded, source, ts, TranscodingSopInstanceUidMode_AllowNew))
       {
         // Transcoding has succeeded
         DcmDataset *stDetailTmp = NULL;
@@ -550,7 +582,6 @@
     localAet_ = context_.GetDefaultLocalApplicationEntityTitle();
     position_ = 0;
     originatorAet_ = originatorAet;
-    unsigned int loaderThreads = 1;
 
     {
       OrthancConfiguration::ReaderLock lock;
@@ -574,11 +605,8 @@
         throw OrthancException(ErrorCode_InexistentItem,
                                "C-GET: Rejecting SCU request from unknown modality with AET: " + originatorAet);
       }
-
-      loaderThreads = lock.GetConfiguration().GetLoaderThreads();
     }
 
-    instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads, false, DicomTransferSyntax_BigEndianExplicit /* dummy unused value */, 0, "CGET"));
     std::vector<FileInfo> filesInfo;
 
     for (std::list<std::string>::const_iterator
@@ -590,11 +618,16 @@
       context_.GetOrderedChildInstances(instancesIds_, filesInfo, *resourceId, level);
     }
 
+
+    instancesLoader_.reset(context_.GetDicomSequentialReaderFactory().CreateForOriginalParsedDicomFile());
+
     for (size_t i = 0; i < instancesIds_.size(); ++i)
     {
-      instancesLoader_->PreloadDicomInstance(instancesIds_[i], filesInfo[i]);
+      instancesLoader_->Submit(filesInfo[i], new ReaderUserData(instancesIds_[i]));
     }
 
+    instancesLoader_->Start();
+
     failedUIDs_.clear();
 
     completedCount_ = 0;
--- a/OrthancServer/Sources/OrthancGetRequestHandler.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancGetRequestHandler.h	Tue Jun 02 07:41:56 2026 +0200
@@ -23,29 +23,28 @@
 #pragma once
 
 #include "../../OrthancFramework/Sources/Compatibility.h"  // For ORTHANC_OVERRIDE
+#include "../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/IGetRequestHandler.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/RemoteModalityParameters.h"
 
-#include <dcmtk/dcmnet/dimse.h>
-
 #include <list>
 
-class DcmFileFormat;
-
 namespace Orthanc
 {
+  class ParsedDicomFile;
   class ServerContext;
-  class ThreadedInstancesLoader;
   
   class OrthancGetRequestHandler : public IGetRequestHandler
   {
   private:
+    class ReaderUserData;
+
     ServerContext& context_;
     std::string localAet_;
     std::vector<std::string> instancesIds_;
     size_t position_;
     std::string originatorAet_;
-    std::unique_ptr<ThreadedInstancesLoader> instancesLoader_;
+    std::unique_ptr<DicomSequentialReader> instancesLoader_;
 
     unsigned int completedCount_;
     unsigned int warningCount_;
@@ -63,7 +62,7 @@
     bool PerformGetSubOp(T_ASC_Association *assoc,
                          const std::string& sopClassUid,
                          const std::string& sopInstanceUid,
-                         DcmFileFormat* datasetRaw);
+                         ParsedDicomFile& dicom);
     
     void AddFailedUIDInstance(const std::string& sopInstance);
 
--- a/OrthancServer/Sources/OrthancMoveRequestHandler.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancMoveRequestHandler.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -27,13 +27,13 @@
 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomConnectionInfo.h"
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
+#include "../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h"
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/MetricsRegistry.h"
 
 #include "OrthancConfiguration.h"
 #include "ServerContext.h"
 #include "ServerJobs/DicomModalityStoreJob.h"
-#include "ServerJobs/ThreadedInstancesLoader.h"
 
 
 namespace Orthanc
@@ -42,14 +42,31 @@
   {
     // Anonymous namespace to avoid clashes between compilation modules
 
+    class MoveReaderUserData : public IDynamicObject
+    {
+    private:
+      std::string instanceId_;
+
+    public:
+      explicit MoveReaderUserData(const std::string& instanceId) :
+        instanceId_(instanceId)
+      {
+      }
+
+      const std::string& GetInstanceId() const
+      {
+        return instanceId_;
+      }
+    };
+
+
     class SynchronousMove : public IMoveRequestIterator
     {
     private:
       ServerContext& context_;
       std::string localAet_;
       std::vector<std::string> instancesIds_;
-      // std::vector<FileInfo> filesInfo_;
-      std::unique_ptr<ThreadedInstancesLoader> instancesLoader_;
+      std::unique_ptr<DicomSequentialReader> instancesLoader_;
       size_t position_;
       RemoteModalityParameters remote_;
       std::string originatorAet_;
@@ -69,12 +86,9 @@
         originatorAet_(originatorAet),
         originatorId_(originatorId)
       {
-        unsigned int loaderThreads;
-
         {
           OrthancConfiguration::ReaderLock lock;
           remote_ = lock.GetConfiguration().GetModalityUsingAet(targetAet);
-          loaderThreads = lock.GetConfiguration().GetLoaderThreads();
         }
 
         if (remote_.HasLocalAet())
@@ -82,8 +96,6 @@
           localAet_ = remote_.GetLocalAet();  // from the DicomModalities config
         }
 
-        instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads, false, DicomTransferSyntax_BigEndianExplicit /* dummy value*/, 0, "CSTO"));
-
         std::vector<FileInfo> filesInfo;
         for (size_t i = 0; i < publicIds.size(); i++)
         {
@@ -95,10 +107,14 @@
           context.GetOrderedChildInstances(instancesIds_, filesInfo, resourceId, resourceType);
         }
 
+        instancesLoader_.reset(context_.GetDicomSequentialReaderFactory().CreateForOriginalRawMemoryBuffer());
+
         for (size_t i = 0; i < instancesIds_.size(); ++i)
         {
-          instancesLoader_->PreloadDicomInstance(instancesIds_[i], filesInfo[i]);
+          instancesLoader_->Submit(filesInfo[i], new MoveReaderUserData(instancesIds_[i]));
         }
+
+        instancesLoader_->Start();
       }
 
       virtual unsigned int GetSubOperationCount() const ORTHANC_OVERRIDE
@@ -113,10 +129,26 @@
           return Status_Failure;
         }
 
+        if (instancesLoader_.get() == NULL ||
+            !instancesLoader_->HasNext())
+        {
+          throw OrthancException(ErrorCode_InternalError);
+        }
+
         const std::string& id = instancesIds_[position_++];
 
-        std::string dicom;
-        instancesLoader_->WaitDicomInstance(dicom, id);
+        std::unique_ptr<DicomSequentialReader::Item> next(instancesLoader_->Next());
+        assert(next.get() != NULL &&
+               next->HasUserData());
+
+        {
+          // This is just a sanity check, the class "MoveReaderUserData" could be removed
+          const MoveReaderUserData& userData = dynamic_cast<const MoveReaderUserData&>(next->GetUserData());
+          if (userData.GetInstanceId() != id)
+          {
+            throw OrthancException(ErrorCode_InternalError);
+          }
+        }
 
         if (connection_.get() == NULL)
         {
@@ -124,8 +156,11 @@
           connection_.reset(new DicomStoreUserConnection(params));
         }
 
+        const IMemoryBuffer& dicom = next->GetRawMemoryBuffer();
+
         std::string sopClassUid, sopInstanceUid;  // Unused
-        context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, *connection_, dicom,
+        context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, *connection_,
+                                              dicom.GetData(), dicom.GetSize(),
                                               true, originatorAet_, originatorId_);
 
         return Status_Success;
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -37,6 +37,7 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string/predicate.hpp>
 
+
 #define INFO_SUBSEQUENCES \
   "Starting with Orthanc 1.9.4, paths to subsequences can be provided using the "\
   "same syntax as the `dcmodify` command-line tool (wildcards are supported as well)."
@@ -216,39 +217,22 @@
 
     std::unique_ptr<ParsedDicomFile> modified;
 
+    if (transcode)
     {
-      ServerContext::DicomCacheLocker locker(context, id);
-      modified.reset(locker.GetDicom().Clone(true));
+      std::unique_ptr<TranscoderDataSource::Transcoded> transcoded(
+        context.ReadTranscodedDicom(id, targetSyntax, TranscodingSopInstanceUidMode_AllowNew, true, lossyQuality));
+
+      TranscoderDataSource::Transcoded::LockAsParsed lock(*transcoded);
+      modified.reset(lock.GetContent().Clone(true));
+    }
+    else
+    {
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id));
+      modified.reset(dicom->Clone());
     }
     
     modification.Apply(modified);
-
-    if (transcode)
-    {
-      IDicomTranscoder::DicomImage source;
-      source.AcquireParsed(*modified);  // "modified" is invalid below this point
-      
-      IDicomTranscoder::DicomImage transcoded;
-
-      std::set<DicomTransferSyntax> s;
-      s.insert(targetSyntax);
-      
-      if (context.GetTranscoder().Transcode(transcoded, source, s, TranscodingSopInstanceUidMode_AllowNew, lossyQuality))
-      {      
-        call.GetOutput().AnswerBuffer(transcoded.GetBufferData(),
-                                      transcoded.GetBufferSize(), MimeType_Dicom);
-      }
-      else
-      {
-        throw OrthancException(ErrorCode_InternalError,
-                               "Cannot transcode to transfer syntax: " +
-                               std::string(GetTransferSyntaxUid(targetSyntax)));
-      }
-    }
-    else
-    {
-      modified->Answer(call.GetOutput());
-    }
+    modified->Answer(call.GetOutput());
   }
 
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -29,6 +29,7 @@
 #include "../../../OrthancFramework/Sources/CompatibilityMath.h"
 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h"
 #include "../../../OrthancFramework/Sources/Constants.h"
+#include "../../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h"
 #include "../../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
@@ -38,7 +39,6 @@
 #include "../../../OrthancFramework/Sources/Images/ImageProcessing.h"
 #include "../../../OrthancFramework/Sources/Images/NumpyWriter.h"
 #include "../../../OrthancFramework/Sources/Logging.h"
-#include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
 
 #include "../OrthancConfiguration.h"
@@ -51,15 +51,6 @@
 // This "include" is mandatory for Release builds using Linux Standard Base
 #include <boost/shared_ptr.hpp>
 
-#include "../../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
-
-/**
- * This semaphore is used to limit the number of concurrent HTTP
- * requests on CPU-intensive routes of the REST API, in order to
- * prevent exhaustion of resources (new in Orthanc 1.7.0).
- **/
-static Orthanc::Semaphore throttlingSemaphore_(4);  // TODO => PARAMETER?
-
 
 static const char* const IGNORE_LENGTH = "ignore-length";
 static const char* const RECONSTRUCT_FILES = "ReconstructFiles";
@@ -382,8 +373,9 @@
           DicomWebJsonVisitor visitor;
           
           {
-            ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
-            locker.GetDicom().Apply(visitor);
+            std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(publicId));
+            DicomDataSource::Dicom::Lock lock(*dicom);
+            lock.GetContent().Apply(visitor);
           }
 
           if (mime == MimeType_DicomWebJson)
@@ -411,38 +403,25 @@
 
     if (call.HasArgument(GET_TRANSCODE))
     {
+      const DicomTransferSyntax transferSyntax = GetTransferSyntax(call.GetArgument(GET_TRANSCODE, ""));
+
       unsigned int lossyQuality;
       unsigned int defaultLossyQuality;
+
       {
         OrthancConfiguration::ReaderLock lock;
         defaultLossyQuality = lock.GetConfiguration().GetDicomLossyTranscodingQuality();
       }
+
       lossyQuality = call.GetUnsignedInteger32Argument(GET_LOSSY_QUALITY, defaultLossyQuality);
 
-      std::string source;
-      std::string attachmentId;
-      std::string transcoded;
-      context.ReadDicom(source, attachmentId, publicId);
-
-      if (lossyQuality != defaultLossyQuality) // we can't use the cache if the lossy quality is not the default one
-      {
-        IDicomTranscoder::DicomImage targetImage;
-        IDicomTranscoder::DicomImage sourceImage;
-        sourceImage.SetExternalBuffer(source);
-        std::set<DicomTransferSyntax> allowedSyntaxes;
-        allowedSyntaxes.insert(GetTransferSyntax(call.GetArgument(GET_TRANSCODE, "")));
-
-        if (context.GetTranscoder().Transcode(targetImage, sourceImage, allowedSyntaxes, TranscodingSopInstanceUidMode_AllowNew, lossyQuality))
-        {
-          call.GetOutput().SetContentFilename(filename.c_str());
-          call.GetOutput().AnswerBuffer(targetImage.GetBufferData(), targetImage.GetBufferSize(), MimeType_Dicom);
-        }
-      }
-      else if (context.TranscodeWithCache(transcoded, source, publicId, attachmentId, GetTransferSyntax(call.GetArgument(GET_TRANSCODE, ""))))
-      {
-        call.GetOutput().SetContentFilename(filename.c_str());
-        call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom);
-      }
+      std::unique_ptr<TranscoderDataSource::Transcoded> transcoded2(
+        context.ReadTranscodedDicom(publicId, transferSyntax, TranscodingSopInstanceUidMode_AllowNew, true, lossyQuality));
+
+      TranscoderDataSource::Transcoded::LockAsBuffer lock(*transcoded2);
+
+      call.GetOutput().SetContentFilename(filename.c_str());
+      call.GetOutput().AnswerBuffer(lock.GetContent(), MimeType_Dicom);
     }
     else
     {
@@ -489,12 +468,14 @@
 
     std::string publicId = call.GetUriComponent("id", "");
 
-    std::string dicom;
-    context.ReadDicom(dicom, publicId);
-
     std::string target;
     call.BodyToString(target);
-    SystemToolbox::WriteFile(dicom, SystemToolbox::PathFromUtf8(target));
+
+    {
+      std::unique_ptr<StorageAreaDataSource::Range> raw(context.ReadRawDicom(publicId));
+      SystemToolbox::WriteFile(raw->GetData(), raw->GetSize(),
+                               SystemToolbox::PathFromUtf8(target), false /* don't automatically call fsync */);
+    }
 
     call.GetOutput().AnswerBuffer("{}", MimeType_Json);
   }
@@ -520,8 +501,9 @@
       Json::Value answer;
 
       {
-        ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
-        locker.GetDicom().DatasetToJson(answer, format, flags,
+        std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(publicId));
+        DicomDataSource::Dicom::Lock lock(*dicom);
+        lock.GetContent().DatasetToJson(answer, format, flags,
                                         ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
       }
 
@@ -634,13 +616,16 @@
       return;
     }
 
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
     std::string publicId = call.GetUriComponent("id", "");
 
     unsigned int numberOfFrames;
       
     {
-      ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
-      numberOfFrames = locker.GetDicom().GetFramesCount();
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(publicId));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+      numberOfFrames = lock.GetContent().GetFramesCount();
     }
     
     Json::Value result = Json::arrayValue;
@@ -923,9 +908,11 @@
              * Retrieve a summary of the DICOM tags, which is
              * necessary to deal with MONOCHROME1 photometric
              * interpretation, and with windowing parameters.
-             **/ 
-            ServerContext::DicomCacheLocker locker(context, publicId);
-            handler.Handle(call, decoded, &locker.GetDicom(), frame);
+             **/
+
+            std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(publicId));
+            DicomDataSource::Dicom::Lock lock(*dicom);
+            handler.Handle(call, decoded, &lock.GetContent(), frame);
           }
           else
           {
@@ -1252,8 +1239,6 @@
   template <enum ImageExtractionMode mode>
   static void GetImage(RestApiGetCall& call)
   {
-    Semaphore::Locker locker(throttlingSemaphore_);
-        
     GetImageHandler handler(mode);
     IDecodedFrameHandler::Apply(call, handler, mode, false /* not rendered */);
   }
@@ -1261,8 +1246,6 @@
 
   static void GetRenderedFrame(RestApiGetCall& call)
   {
-    Semaphore::Locker locker(throttlingSemaphore_);
-        
     RenderedFrameHandler handler;
     IDecodedFrameHandler::Apply(call, handler, ImageExtractionMode_Preview /* arbitrary value */, true);
   }
@@ -1393,6 +1376,8 @@
     }
     else
     {
+      ServerContext& context = OrthancRestApi::GetContext(call);
+
       const std::string instanceId = call.GetUriComponent("id", "");
       const bool compress = call.GetBooleanArgument("compress", false);
       const bool rescale = call.GetBooleanArgument("rescale", true);
@@ -1406,10 +1391,9 @@
       NumpyVisitor visitor(0 /* no depth, 2D frame */, rescale);
 
       {
-        Semaphore::Locker throttling(throttlingSemaphore_);
-        ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), instanceId);
-        
-        visitor.WriteFrame(locker.GetDicom(), frame);
+        std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(instanceId));
+        DicomDataSource::Dicom::Lock lock(*dicom);
+        visitor.WriteFrame(lock.GetContent(), frame);
       }
 
       visitor.Answer(call.GetOutput(), compress);
@@ -1430,15 +1414,17 @@
     }
     else
     {
+      ServerContext& context = OrthancRestApi::GetContext(call);
+
       const std::string instanceId = call.GetUriComponent("id", "");
       const bool compress = call.GetBooleanArgument("compress", false);
       const bool rescale = call.GetBooleanArgument("rescale", true);
 
       {
-        Semaphore::Locker throttling(throttlingSemaphore_);
-        ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), instanceId);
-
-        const unsigned int depth = locker.GetDicom().GetFramesCount();
+        std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(instanceId));
+        DicomDataSource::Dicom::Lock lock(*dicom);
+
+        const unsigned int depth = lock.GetContent().GetFramesCount();
         if (depth == 0)
         {
           throw OrthancException(ErrorCode_BadFileFormat, "Empty DICOM instance");
@@ -1448,7 +1434,7 @@
 
         for (unsigned int frame = 0; frame < depth; frame++)
         {
-          visitor.WriteFrame(locker.GetDicom(), frame);
+          visitor.WriteFrame(lock.GetContent(), frame);
         }
 
         visitor.Answer(call.GetOutput(), compress);
@@ -1474,8 +1460,6 @@
       const bool compress = call.GetBooleanArgument("compress", false);
       const bool rescale = call.GetBooleanArgument("rescale", true);
 
-      Semaphore::Locker throttling(throttlingSemaphore_);
-
       ServerIndex& index = OrthancRestApi::GetIndex(call);
       SliceOrdering ordering(index, seriesId);
 
@@ -1495,11 +1479,12 @@
         unsigned int framesCount = ordering.GetFramesCount(i);
 
         {
-          ServerContext::DicomCacheLocker locker(context, instanceId);
+          std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(instanceId));
+          DicomDataSource::Dicom::Lock lock(*dicom);
 
           for (unsigned int frame = 0; frame < framesCount; frame++)
           {
-            visitor.WriteFrame(locker.GetDicom(), frame);
+            visitor.WriteFrame(lock.GetContent(), frame);
           }
         }
       }
@@ -1536,8 +1521,6 @@
       return;
     }
 
-    Semaphore::Locker locker(throttlingSemaphore_);
-        
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     std::string frameId = call.GetUriComponent("frame", "0");
@@ -1594,7 +1577,9 @@
       }
       return;
     }
-    
+
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
     std::string frameId = call.GetUriComponent("frame", "0");
 
     unsigned int frame;
@@ -1612,8 +1597,9 @@
     MimeType mime;
 
     {
-      ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
-      locker.GetDicom().GetRawFrame(raw, mime, frame);
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(publicId));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+      lock.GetContent().GetRawFrame(raw, mime, frame);
     }
 
     if (GzipCompression)
@@ -2378,13 +2364,12 @@
 
       if (hasRangeHeader)
       {
-        std::string fragment;
-        context.ReadAttachmentRange(fragment, info, range, uncompress);
+        std::unique_ptr<StorageAreaDataSource::Range> fragment(context.ReadAttachment(info, range, uncompress));
 
         uint64_t fullSize = (uncompress ? info.GetUncompressedSize() : info.GetCompressedSize());
         call.GetOutput().GetLowLevelOutput().SetContentType(MimeType_Binary);
         call.GetOutput().GetLowLevelOutput().AddHeader("Content-Range", range.FormatHttpContentRange(fullSize));
-        call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_206_PartialContent, fragment);
+        call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_206_PartialContent, fragment->GetData(), fragment->GetSize());
       }
       else if (uncompress ||
                info.GetCompressionType() == CompressionType_None)
@@ -2394,9 +2379,8 @@
       else
       {
         // Access to the raw attachment (which is compressed)
-        std::string content;
-        context.ReadAttachment(content, info, false /* don't uncompress */, true /* skip cache */);
-        call.GetOutput().AnswerBuffer(content, MimeType_Binary);
+        std::unique_ptr<StorageAreaDataSource::Range> content(context.ReadAttachment(info, false /* don't uncompress */));
+        call.GetOutput().AnswerBuffer(content->GetData(), content->GetSize(), MimeType_Binary);
       }
     }
   }
@@ -2574,13 +2558,14 @@
     bool ok = false;
 
     // First check whether the compressed data is correctly stored in the disk
-    std::string data;
-    context.ReadAttachment(data, info, false, true /* skipCache when you absolutely need the compressed data */);
-
-    std::string actualMD5;
-    Toolbox::ComputeMD5(actualMD5, data);
+    std::string compressedMD5;
+
+    {
+      std::unique_ptr<StorageAreaDataSource::Range> compressed(context.ReadAttachment(info, false /* don't uncompress */));
+      Toolbox::ComputeMD5(compressedMD5, compressed->GetData(), compressed->GetSize());
+    }
     
-    if (actualMD5 == info.GetCompressedMD5())
+    if (compressedMD5 == info.GetCompressedMD5())
     {
       // The compressed data is OK. If a compression algorithm was
       // applied to it, now check the MD5 of the uncompressed data.
@@ -2590,9 +2575,14 @@
       }
       else
       {
-        context.ReadAttachment(data, info, true, true /* skipCache when you absolutely need the compressed data */);
-        Toolbox::ComputeMD5(actualMD5, data);
-        ok = (actualMD5 == info.GetUncompressedMD5());
+        std::string uncompressedMD5;
+
+        {
+          std::unique_ptr<StorageAreaDataSource::Range> uncompressed(context.ReadAttachment(info, true /* uncompress */));
+          Toolbox::ComputeMD5(uncompressedMD5, uncompressed->GetData(), uncompressed->GetSize());
+        }
+
+        ok = (uncompressedMD5 == info.GetUncompressedMD5());
       }
     }
 
@@ -2827,11 +2817,15 @@
       return;
     }
 
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
     std::string id = call.GetUriComponent("id", "");
 
-    ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
-
-    locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri());
+    {
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+      lock.GetContent().SendPathValue(call.GetOutput(), call.GetTrailingUri());
+    }
   }
 
 
@@ -3794,14 +3788,20 @@
       return;
     }
 
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
     const std::string id = call.GetUriComponent("id", "");
-    std::string pdf;
-    ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
-
-    if (locker.GetDicom().ExtractPdf(pdf))
+
     {
-      call.GetOutput().AnswerBuffer(pdf, MimeType_Pdf);
-      return;
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+
+      std::string pdf;
+      if (lock.GetContent().ExtractPdf(pdf))
+      {
+        call.GetOutput().AnswerBuffer(pdf, MimeType_Pdf);
+        return;
+      }
     }
   }
 
@@ -3861,16 +3861,16 @@
 
     std::string publicId = call.GetUriComponent("id", "");
 
-    std::string dicomContent;
-    context.ReadDicomForHeader(dicomContent, publicId);
-
-    // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to
-    // speed up things here
-
-    ParsedDicomFile dicom(dicomContent);
-
     Json::Value header;
-    OrthancConfiguration::DefaultDicomHeaderToJson(header, dicom);
+
+    {
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadDicomUntilPixelData(publicId));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+
+      // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to
+      // speed up things here
+      OrthancConfiguration::DefaultDicomHeaderToJson(header, lock.GetContent());
+    }
 
     AnswerDicomAsJson(call, header, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full));
   }
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -1005,8 +1005,6 @@
     registry.SetIntegerValue("orthanc_up_time_s", serverUpTime);
     registry.SetIntegerValue("orthanc_last_change", lastChange["Last"].asInt64());
 
-    context.PublishCacheMetrics();
-
     std::string s;
     registry.ExportPrometheusText(s);
 
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -226,7 +226,11 @@
           time_ = GetNow();
         }
 
-        context_.ReadDicom(target_, resource.GetIdentifier());
+        {
+          std::unique_ptr<StorageAreaDataSource::Range> raw(context_.ReadRawDicom(resource.GetIdentifier()));
+          raw->Copy(target_);
+        }
+
         success_ = true;
       }
     }
@@ -482,7 +486,12 @@
         try
         {
           mime = MimeType_Dicom;
-          context_.ReadDicom(content, instanceId);
+
+          {
+            std::unique_ptr<StorageAreaDataSource::Range> raw(context_.ReadRawDicom(instanceId));
+            raw->Copy(content);
+          }
+
           LookupTime(time, context_, instanceId, ResourceType_Instance, MetadataType_Instance_ReceptionDate);
           return true;
         }
--- a/OrthancServer/Sources/ServerContext.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -25,6 +25,10 @@
 #include "ServerContext.h"
 
 #include "../../OrthancFramework/Sources/Cache/SharedArchive.h"
+#include "../../OrthancFramework/Sources/Compression/ZlibCompressor.h"
+#include "../../OrthancFramework/Sources/Constants.h"
+#include "../../OrthancFramework/Sources/DataSource/DataSourceReader.h"
+#include "../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomElement.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomStreamReader.h"
@@ -38,19 +42,21 @@
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/MallocMemoryBuffer.h"
 #include "../../OrthancFramework/Sources/MetricsRegistry.h"
+#include "../../OrthancFramework/Sources/MultiThreading/ThreadPool.h"
 #include "../../OrthancFramework/Sources/SerializationToolbox.h"
 #include "../Plugins/Engine/OrthancPlugins.h"
 
 #include "DicomInstanceToStore.h"
 #include "OrthancConfiguration.h"
 #include "OrthancRestApi/OrthancRestApi.h"
+#include "OutgoingDicomInstance.h"
 #include "ResourceFinder.h"
 #include "Search/DatabaseLookup.h"
 #include "ServerJobs/OrthancJobUnserializer.h"
 #include "ServerToolbox.h"
+#include "ServerTranscoder.h"
+#include "SimpleInstanceOrdering.h"
 #include "StorageCommitmentReports.h"
-#include "OutgoingDicomInstance.h"
-#include "SimpleInstanceOrdering.h"
 
 #include <dcmtk/dcmdata/dcfilefo.h>
 #include <dcmtk/dcmnet/dimse.h>
@@ -63,7 +69,29 @@
 #  include <malloc.h>
 #endif
 
-static size_t DICOM_CACHE_SIZE = static_cast<size_t>(128) * 1024 * 1024;  // 128 MB
+
+// Those metrics correspond to those found in StorageAccessor in Orthanc <= 1.12.11
+static const char* const METRICS_STORAGE_AREA_READ_BYTES = "orthanc_storage_read_bytes";
+static const char* const METRICS_STORAGE_AREA_READ_DURATION = "orthanc_storage_read_duration_ms";
+static const char* const METRICS_STORAGE_AREA_WRITTEN_BYTES = "orthanc_storage_written_bytes";
+
+
+
+static const char* const METRICS_STORAGE_AREA_CACHE_COUNT = "orthanc_storage_cache_count";
+static const char* const METRICS_STORAGE_AREA_CACHE_HIT_COUNT = "orthanc_storage_cache_hit_count";
+static const char* const METRICS_STORAGE_AREA_CACHE_MISS_COUNT = "orthanc_storage_cache_miss_count";
+static const char* const METRICS_STORAGE_AREA_CACHE_SIZE_MB = "orthanc_storage_cache_size_mb";
+
+static const char* const METRICS_DICOM_CACHE_COUNT = "orthanc_dicom_cache_count";
+static const char* const METRICS_DICOM_CACHE_HIT_COUNT = "orthanc_dicom_cache_hit_count";
+static const char* const METRICS_DICOM_CACHE_MISS_COUNT = "orthanc_dicom_cache_miss_count";
+static const char* const METRICS_DICOM_CACHE_SIZE_MB = "orthanc_dicom_cache_size_mb";
+
+static const char* const METRICS_TRANSCODER_CACHE_COUNT = "orthanc_transcoder_cache_count";
+static const char* const METRICS_TRANSCODER_CACHE_HIT_COUNT = "orthanc_transcoder_cache_hit_count";
+static const char* const METRICS_TRANSCODER_CACHE_MISS_COUNT = "orthanc_transcoder_cache_miss_count";
+static const char* const METRICS_TRANSCODER_CACHE_SIZE_MB = "orthanc_transcoder_cache_size_mb";
+
 
 
 /**
@@ -357,21 +385,9 @@
   }
 
 
-  void ServerContext::PublishCacheMetrics()
-  {
-    metricsRegistry_->SetFloatValue("orthanc_dicom_cache_size_mb",
-                                    static_cast<float>(dicomCache_.GetCurrentSize()) / static_cast<float>(1024 * 1024));
-    metricsRegistry_->SetIntegerValue("orthanc_dicom_cache_count", 
-                                    static_cast<int64_t>(dicomCache_.GetNumberOfItems()));
-    metricsRegistry_->SetFloatValue("orthanc_storage_cache_size_mb",
-                                    static_cast<float>(storageCache_.GetCurrentSize()) / static_cast<float>(1024 * 1024));
-    metricsRegistry_->SetIntegerValue("orthanc_storage_cache_count", 
-                                    static_cast<int64_t>(storageCache_.GetNumberOfItems()));
-  }
-
-
   ServerContext::ServerContext(IDatabaseWrapper& database,
                                IPluginStorageArea& area,
+                               ServerTranscoder* transcoder /* takes ownership */,
                                bool unitTesting,
                                size_t maxCompletedJobs,
                                bool readOnly) :
@@ -380,7 +396,6 @@
     compressionEnabled_(false),
     storeMD5_(true),
     largeDicomThrottler_(1),
-    dicomCache_(DICOM_CACHE_SIZE),
     mainLua_(*this),
     filterLua_(*this),
     luaListener_(*this),
@@ -396,6 +411,8 @@
     isExecuteLuaEnabled_(false),
     isRestApiWriteToFileSystemEnabled_(false),
     overwriteInstances_(OverwriteInstancesMode_Never),
+    transcoder_(transcoder),
+    transcodeDicomProtocol_(true),
     isIngestTranscoding_(false),
     ingestTranscodingOfUncompressed_(true),
     ingestTranscodingOfCompressed_(true),
@@ -407,6 +424,8 @@
   {
     try
     {
+      bool checkMD5 = true;
+
       {
         OrthancConfiguration::ReaderLock lock;
 
@@ -532,6 +551,8 @@
         SetAcceptedSopClasses(acceptedSopClasses, rejectedSopClasses);
 
         defaultDicomRetrieveMethod_ = StringToRetrieveMethod(lock.GetConfiguration().GetDicomDefaultRetrieveMethod());
+
+        checkMD5 = lock.GetConfiguration().GetBooleanParameter("CheckMD5", true);  // TODO-Streaming - Parameter
       }
 
       jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200);
@@ -546,6 +567,98 @@
 #else
       LOG(INFO) << "Your platform does not support malloc_trim(), not starting the memory trimming thread";
 #endif
+
+      // For streaming
+      {
+        boost::shared_ptr<ThreadPool> pool(new ThreadPool);
+        pool->SetCountThreads(4);  // TODO-Streaming - Parameter
+        pool->SetLoggingThreadName("STORAGE");
+        pool->SetDequeueTimeout(100);
+        pool->Start();
+
+        std::unique_ptr<StorageAreaDataSource> source(new StorageAreaDataSource(area_, checkMD5));
+        source->SetMetricsRegistry(metricsRegistry_,
+                                   METRICS_STORAGE_AREA_READ_BYTES, METRICS_STORAGE_AREA_READ_DURATION);
+
+        storageAreaReader_.reset(new DataSourceReader(pool, source.release()));
+        storageAreaReader_->SetMetricsConfiguration(
+          DataSourceReader::MetricsConfiguration(metricsRegistry_,
+                                                 METRICS_STORAGE_AREA_CACHE_SIZE_MB,
+                                                 METRICS_STORAGE_AREA_CACHE_COUNT,
+                                                 METRICS_STORAGE_AREA_CACHE_HIT_COUNT,
+                                                 METRICS_STORAGE_AREA_CACHE_MISS_COUNT));
+
+        //storageAreaReader_->SetCapacity(1);  // To test on highest pressure
+        storageAreaReader_->SetCapacity(256 * MEGABYTE); // TODO-Streaming - Parameter
+
+        //storageAreaReader_->CreateCache(256 * MEGABYTE); // TODO-Streaming - Parameter
+        storageAreaReader_->CreateCache(1 * GIGABYTE); // TODO-Streaming - Parameter
+      }
+
+      {
+        boost::shared_ptr<ThreadPool> pool(new ThreadPool);
+        pool->SetCountThreads(2);  // TODO-Streaming - Parameter
+        pool->SetLoggingThreadName("DICOM");
+        pool->SetDequeueTimeout(100);
+        pool->Start();
+
+        dicomReader_.reset(new DataSourceReader(pool, new DicomDataSource(storageAreaReader_)));
+        dicomReader_->SetMetricsConfiguration(
+          DataSourceReader::MetricsConfiguration(metricsRegistry_,
+                                                 METRICS_DICOM_CACHE_SIZE_MB,
+                                                 METRICS_DICOM_CACHE_COUNT,
+                                                 METRICS_DICOM_CACHE_HIT_COUNT,
+                                                 METRICS_DICOM_CACHE_MISS_COUNT));
+
+        //dicomReader_->SetCapacity(1);  // To test on highest pressure
+        dicomReader_->SetCapacity(256 * MEGABYTE); // TODO-Streaming - Parameter
+
+        dicomReader_->CreateCache(256 * MEGABYTE); // TODO-Streaming - Parameter
+      }
+
+      if (transcoder_.get() != NULL)
+      {
+        boost::shared_ptr<ThreadPool> pool(new ThreadPool);
+        pool.reset(new ThreadPool);
+        pool->SetCountThreads(2);  // TODO-Streaming - Parameter
+        pool->SetLoggingThreadName("TRANSCODER");
+        pool->SetDequeueTimeout(100);
+        pool->Start();
+
+        transcoderReader_.reset(new DataSourceReader(pool, new TranscoderDataSource(transcoder_, storageAreaReader_)));
+        transcoderReader_->SetMetricsConfiguration(
+          DataSourceReader::MetricsConfiguration(metricsRegistry_,
+                                                 METRICS_TRANSCODER_CACHE_SIZE_MB,
+                                                 METRICS_TRANSCODER_CACHE_COUNT,
+                                                 METRICS_TRANSCODER_CACHE_HIT_COUNT,
+                                                 METRICS_TRANSCODER_CACHE_MISS_COUNT));
+
+        //transcoderReader_->SetCapacity(1);  // To test on highest pressure
+        transcoderReader_->SetCapacity(256 * MEGABYTE); // TODO-Streaming - Parameter
+
+        transcoderReader_->CreateCache(256 * MEGABYTE); // TODO-Streaming - Parameter
+      }
+
+      {
+        unsigned int loaderThreads;
+
+        {
+          OrthancConfiguration::ReaderLock lock;
+          loaderThreads = lock.GetConfiguration().GetLoaderThreads();
+        }
+
+        std::unique_ptr<ThreadPool> pool(new ThreadPool);
+        pool->SetCountThreads(loaderThreads);  // TODO-Streaming - Check
+        pool->SetLoggingThreadName("READER");
+        pool->SetDequeueTimeout(100);
+        pool->Start();
+
+        boost::shared_ptr<IExecutorService> executor(pool.release());
+        dicomSequentialReaderFactory_.reset(new DicomSequentialReader::Factory(
+                                              executor, storageAreaReader_, dicomReader_, transcoderReader_,
+                                              4 /* TODO-Streaming: Parameter */,
+                                              0  /* TODO-Streaming: Parameter */));
+      }
     }
     catch (OrthancException&)
     {
@@ -638,11 +751,17 @@
                                  FileContentType type,
                                  const std::string& customData)
   {
-    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
+    StorageAccessor accessor(area_, *metricsRegistry_);
     accessor.Remove(fileUuid, type, customData);
   }
 
 
+  void ServerContext::RemoveFile(const FileInfo& attachment)
+  {
+    RemoveFile(attachment.GetUuid(), attachment.GetContentType(), attachment.GetCustomData());
+  }
+
+
   ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId,
                                                                   DicomInstanceToStore& dicom,
                                                                   bool isReconstruct)
@@ -700,7 +819,6 @@
     try
     {
       MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
-      StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
 
       DicomInstanceHasher hasher(summary);
       resultPublicId = hasher.HashInstance();
@@ -791,12 +909,6 @@
         return result;
       }
 
-      // Remove the file from the DicomCache
-      // If this is a new instance, this is a no-op
-      // If overwriteMode == OverwriteInstancesMode_IfChanged and the file has not changed, we won't reach this point
-      // If overwriteMode == OverwriteInstancesMode_Always, then, let's always invalidate even if it is meaningful only if the file has changed (note: there is a TODO about cache and MD5)
-      dicomCache_.Invalidate(resultPublicId);
-
       // TODO Should we use "gzip" instead?
       CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
 
@@ -805,7 +917,10 @@
 
       if (!isAdoption)
       {
-        accessor.Write(dicomInfo, dicom.GetBufferData(), dicom.GetBufferSize(), FileContentType_Dicom, compression, dicomMd5, storeMD5_, &dicom);
+        StorageAccessor accessor(area_, *metricsRegistry_);
+        accessor.Write(dicomInfo, dicom.GetBufferData(), dicom.GetBufferSize(),
+                       FileContentType_Dicom, compression, dicomMd5, storeMD5_, &dicom);
+
         attachments.push_back(dicomInfo);
       }
       else
@@ -818,7 +933,10 @@
           (!area_.HasEfficientReadRange() ||
            compressionEnabled_))
       {
-        accessor.Write(dicomUntilPixelData, dicom.GetBufferData(), pixelDataOffset, FileContentType_DicomUntilPixelData, compression, storeMD5_, NULL);
+        StorageAccessor accessor(area_, *metricsRegistry_);
+        accessor.Write(dicomUntilPixelData, dicom.GetBufferData(), pixelDataOffset,
+                       FileContentType_DicomUntilPixelData, compression, storeMD5_, NULL);
+
         attachments.push_back(dicomUntilPixelData);
       }
 
@@ -842,11 +960,11 @@
           LOG(ERROR) << "Unexpected error while storing an instance in DB, cancelling and deleting the attachments: " << ex.GetDetails();
         }
 
-        accessor.Remove(dicomInfo);
+        RemoveFile(dicomInfo);
 
         if (dicomUntilPixelData.IsValid())
         {
-          accessor.Remove(dicomUntilPixelData);
+          RemoveFile(dicomUntilPixelData);
         }
         
         throw;
@@ -865,12 +983,12 @@
       {
         if (!isAdoption)
         {
-          accessor.Remove(dicomInfo);
+          RemoveFile(dicomInfo);
         }
 
         if (dicomUntilPixelData.IsValid())
         {
-          accessor.Remove(dicomUntilPixelData);
+          RemoveFile(dicomUntilPixelData);
         }
       }
 
@@ -1074,7 +1192,7 @@
           imageInfo.ThrowIfInvalidFrameSize();
         }
 
-        if (GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew /* allow new SOP instance UID */))
+        if (GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew /* allow new SOP instance UID */))
         {
           std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());
 
@@ -1110,8 +1228,15 @@
                                        const FileInfo& attachment,
                                        const std::string& filename)
   {
-    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-    accessor.AnswerFile(output, attachment, GetFileContentMime(attachment.GetContentType()), filename);
+    std::unique_ptr<StorageAreaDataSource::Range> range(ReadAttachment(attachment, true /* uncompress */));
+
+    BufferHttpSender sender;
+    sender.SetBuffer(range->GetData(), range->GetSize());
+    sender.SetContentType(GetFileContentMime(attachment.GetContentType()));
+    sender.SetContentFilename(filename);
+
+    HttpStreamTranscoder transcoder(sender, CompressionType_None);
+    output.AnswerStream(transcoder);
   }
 
 
@@ -1138,13 +1263,15 @@
       return;
     }
 
-    std::string content;
-
-    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-    accessor.Read(content, attachment);
 
     FileInfo modified;
-    accessor.Write(modified, content.empty() ? NULL : content.c_str(), content.size(), attachmentType, compression, storeMD5_, NULL);
+
+    {
+      std::unique_ptr<StorageAreaDataSource::Range> range(ReadAttachment(attachment, true /* uncompress */));
+
+      StorageAccessor accessor(area_, *metricsRegistry_);
+      accessor.Write(modified, range->GetData(), range->GetSize(), attachmentType, compression, storeMD5_, NULL);
+    }
 
     try
     {
@@ -1153,13 +1280,13 @@
                                                 true, revision, modified.GetUncompressedMD5());
       if (status != StoreStatus_Success)
       {
-        accessor.Remove(modified);
+        RemoveFile(modified);
         throw OrthancException(ErrorCode_Database);
       }
     }
     catch (OrthancException&)
     {
-      accessor.Remove(modified);
+      RemoveFile(modified);
       throw;
     }    
   }
@@ -1272,15 +1399,14 @@
 
     if (LookupAttachment(attachment, FileContentType_DicomUntilPixelData, instanceAttachments))
     {
-      std::string dicom;
+      std::unique_ptr<DicomDataSource::Dicom> dicom(
+        DicomDataSource::Execute(*dicomReader_, DicomDataSource::CreateWholeRequest(attachment)));
 
       {
-        StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-        accessor.Read(dicom, attachment);
+        DicomDataSource::Dicom::Lock lock(*dicom);
+        OrthancConfiguration::DefaultDicomDatasetToJson(result, lock.GetContent(), ignoreTagLength);
       }
 
-      ParsedDicomFile parsed(dicom);
-      OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength);
       InjectEmptyPixelData(result);
     }
     else
@@ -1321,17 +1447,15 @@
          * this case cannot be used if "StorageCompression" option is
          * "true".
          **/
-      
-        std::string dicom;
-        
+
+        std::unique_ptr<DicomDataSource::Dicom> dicom(
+          DicomDataSource::Execute(*dicomReader_, DicomDataSource::CreateUntilPixelDataRequest(attachment, pixelDataOffset)));
+
         {
-          StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-          accessor.ReadStartRange(dicom, attachment, pixelDataOffset);
+          DicomDataSource::Dicom::Lock lock(*dicom);
+          OrthancConfiguration::DefaultDicomDatasetToJson(result, lock.GetContent(), ignoreTagLength);
         }
         
-        assert(dicom.size() == pixelDataOffset);
-        ParsedDicomFile parsed(dicom);
-        OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength);
         InjectEmptyPixelData(result);
       }
       else if (ignoreTagLength.empty() &&
@@ -1344,15 +1468,10 @@
          * "/tools/invalidate-tags" or to one flavors of
          * "/.../.../reconstruct" will disable this case.
          **/
-      
-        std::string dicomAsJson;
 
-        {
-          StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-          accessor.Read(dicomAsJson, attachment);
-        }
+        std::unique_ptr<StorageAreaDataSource::Range> dicomAsJson(ReadAttachment(attachment, true /* uncompress */));
 
-        if (!Toolbox::ReadJson(result, dicomAsJson))
+        if (!Toolbox::ReadJson(result, dicomAsJson->GetData(), dicomAsJson->GetSize()))
         {
           throw OrthancException(ErrorCode_CorruptedFile,
                                  "Corrupted DICOM-as-JSON attachment of instance: " + instancePublicId);
@@ -1366,25 +1485,32 @@
          * file from the storage area.
          **/
 
-        std::string dicom;
-        ReadDicom(dicom, instancePublicId);
+        if (!LookupAttachment(attachment, FileContentType_Dicom, instanceAttachments))
+        {
+          throw OrthancException(ErrorCode_UnknownResource);
+        }
 
-        ParsedDicomFile parsed(dicom);
-        OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength);
+        std::unique_ptr<StorageAreaDataSource::Range> range(ReadAttachment(attachment, true /* uncompress */));
+
+        // We don't use the cache, as this would complexify the code for a rare edge case
+        ParsedDicomFile dicom(range->GetData(), range->GetSize());
+        OrthancConfiguration::DefaultDicomDatasetToJson(result, dicom, ignoreTagLength);
 
         if (!hasPixelDataOffset)
         {
           /**
-           * The pixel data offset was never computed for this
+           * (*) The pixel data offset was never computed for this
            * instance, which indicates that it was created using
            * Orthanc <= 1.9.0, or that calls to
            * "LookupPixelDataOffset()" from earlier versions of
            * Orthanc have failed. Try again this precomputation now
            * for future calls.
            **/
+
           ValueRepresentation pixelDataVR;
-          if (DicomStreamReader::LookupPixelDataOffset(pixelDataOffset, pixelDataVR, dicom) &&
-              pixelDataOffset < dicom.size())
+          if (DicomStreamReader::LookupPixelDataOffset(
+                pixelDataOffset, pixelDataVR, range->GetData(), range->GetSize()) &&
+              pixelDataOffset < range->GetSize())
           {
             index_.OverwriteMetadata(instancePublicId, MetadataType_Instance_PixelDataOffset,
                                      boost::lexical_cast<std::string>(pixelDataOffset));
@@ -1394,8 +1520,8 @@
             {
               int64_t newRevision;
               AddAttachment(newRevision, instancePublicId, ResourceType_Instance, FileContentType_DicomUntilPixelData,
-                            dicom.empty() ? NULL: dicom.c_str(), pixelDataOffset,
-                             false /* no old revision */, -1 /* dummy revision */, "" /* dummy MD5 */);
+                            range->GetData(), pixelDataOffset,
+                            false /* no old revision */, -1 /* dummy revision */, "" /* dummy MD5 */);
             }
           }
         }
@@ -1412,227 +1538,103 @@
   }
 
 
-  void ServerContext::ReadDicom(std::string& dicom,
-                                std::string& attachmentId,
-                                const std::string& instancePublicId)
-  {
-    std::unique_ptr<Semaphore::Locker> dummyLargeDicomLocker;  // only the DicomCacheLocker uses a real largeDicomLocker_
-    ReadDicomInternal(dicom, attachmentId, instancePublicId, dummyLargeDicomLocker, 0);
-  }
-
-  void ServerContext::ReadDicomInternal(std::string& dicom,
-                                        std::string& attachmentId,
-                                        const std::string& instancePublicId,
-                                        std::unique_ptr<Semaphore::Locker>& largeDicomLocker,
-                                        std::size_t largeDicomThreshold)
+  FileInfo ServerContext::LookupDicomForInstance(const std::string& instancePublicId)
   {
     FileInfo attachment;
     int64_t revision;
 
-    if (!index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom))
+    if (index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom))
+    {
+      return attachment;
+    }
+    else
     {
       throw OrthancException(ErrorCode_InternalError,
                              "Unable to read attachment " + EnumerationToString(FileContentType_Dicom) +
                              " of instance " + instancePublicId);
     }
+  }
 
-    assert(attachment.GetContentType() == FileContentType_Dicom);
-    attachmentId = attachment.GetUuid();
 
-    if (attachment.GetUncompressedSize() < largeDicomThreshold)  // release ASAP (before the read) if we don't plan to hold the lock (https://discourse.orthanc-server.org/t/patch-release-large-dicom-semaphore-lock-early-for-better-performance/6440)
-    {
-      largeDicomLocker.reset(NULL);
-    }
-
-    ReadAttachment(dicom, attachment, true /* uncompress */);
+  StorageAreaDataSource::Range* ServerContext::ReadAttachment(const FileInfo& attachment,
+                                                              bool uncompress)
+  {
+    return StorageAreaDataSource::Execute(
+      *storageAreaReader_, StorageAreaDataSource::CreateAttachmentRequest(attachment, uncompress));
   }
 
 
-  void ServerContext::ReadDicom(std::string& dicom,
-                                const std::string& instancePublicId)
+  StorageAreaDataSource::Range* ServerContext::ReadAttachment(const FileInfo& attachment,
+                                                              const StorageRange& range,
+                                                              bool uncompress)
   {
-    std::string attachmentId;
-    ReadDicom(dicom, attachmentId, instancePublicId);    
+    return StorageAreaDataSource::ReadRange(*storageAreaReader_, attachment, range, uncompress);
   }
 
-  void ServerContext::ReadDicomInternal(std::string& dicom,
-                                        const std::string& instancePublicId,
-                                        std::unique_ptr<Semaphore::Locker>& largeDicomLocker,
-                                        std::size_t largeDicomThreshold)
+
+  StorageAreaDataSource::Range* ServerContext::ReadRawDicom(const std::string& instancePublicId)
   {
-    std::string attachmentId;
-    ReadDicomInternal(dicom, attachmentId, instancePublicId, largeDicomLocker, largeDicomThreshold);
+    return ReadAttachment(LookupDicomForInstance(instancePublicId), true /* uncompress */);
   }
 
-  void ServerContext::ReadDicomForHeader(std::string& dicom,
-                                         const std::string& instancePublicId)
+
+  DicomDataSource::Dicom* ServerContext::ReadParsedDicom(const std::string& instancePublicId)
   {
-    if (!ReadDicomUntilPixelData(dicom, instancePublicId))
-    {
-      ReadDicom(dicom, instancePublicId);
-    }
+    return DicomDataSource::Execute(*dicomReader_, DicomDataSource::CreateWholeRequest(LookupDicomForInstance(instancePublicId)));
   }
 
-  bool ServerContext::ReadDicomUntilPixelData(std::string& dicom,
-                                              const std::string& instancePublicId)
+
+  DicomDataSource::Dicom* ServerContext::ReadDicomUntilPixelData(const std::string& instancePublicId)
   {
     FileInfo attachment;
     int64_t revision;  // Ignored
-    if (index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_DicomUntilPixelData))
-    {
-      StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
 
-      accessor.Read(dicom, attachment);
-      assert(dicom.size() == attachment.GetUncompressedSize());
-
-      return true;
-    }
-
-    if (!area_.HasEfficientReadRange())
-    {
-      return false;
-    }
-    
-    if (!index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom))
-    {
-      throw OrthancException(ErrorCode_InternalError,
-                             "Unable to read the DICOM file of instance " + instancePublicId);
-    }
-
-    std::string s;
-
-    if (attachment.GetCompressionType() == CompressionType_None &&
-        index_.LookupMetadata(s, instancePublicId, ResourceType_Instance,
-                              MetadataType_Instance_PixelDataOffset) &&
-        !s.empty())
+    if (index_.LookupAttachment(attachment, revision, ResourceType_Instance,
+                                instancePublicId, FileContentType_DicomUntilPixelData))
     {
-      uint64_t pixelDataOffset = 0;
-
-      if (SerializationToolbox::ParseUnsignedInteger64(pixelDataOffset, s))
-      {
-        StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-
-        accessor.ReadStartRange(dicom, attachment, pixelDataOffset);
-        assert(dicom.size() == pixelDataOffset);
-        
-        return true;   // Success
-      }
-      else
-      {
-        LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId;
-      }
-    }
-
-    return false;
-  }
-  
-
-  void ServerContext::ReadAttachment(std::string& result,
-                                     const FileInfo& attachment,
-                                     bool uncompressIfNeeded,
-                                     bool skipCache)
-  {
-    std::unique_ptr<StorageAccessor> accessor;
-      
-    if (skipCache)
-    {
-      accessor.reset(new StorageAccessor(area_, GetMetricsRegistry()));
+      return DicomDataSource::Execute(*dicomReader_, DicomDataSource::CreateWholeRequest(attachment));
     }
     else
     {
-      accessor.reset(new StorageAccessor(area_, storageCache_, GetMetricsRegistry()));
-    }
+      attachment = LookupDicomForInstance(instancePublicId);
+
+      std::string metadata;
 
-    if (uncompressIfNeeded)
-    {
-      accessor->Read(result, attachment);
-    }
-    else
-    {
-      // Do not uncompress the content of the storage area, return the
-      // raw data
-      accessor->ReadRaw(result, attachment);
-    }
-  }
-
-  void ServerContext::ReadAttachmentRange(std::string &result,
-                                          const FileInfo &attachment,
-                                          const StorageRange &range,
-                                          bool uncompressIfNeeded)
-  {
-    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-    accessor.ReadRange(result, attachment, range, uncompressIfNeeded);
-  }
-
+      if (attachment.GetCompressionType() == CompressionType_None &&
+          index_.LookupMetadata(metadata, instancePublicId, ResourceType_Instance,
+                                MetadataType_Instance_PixelDataOffset) &&
+          !metadata.empty())
+      {
+        uint64_t pixelDataOffset = 0;
 
-  ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& context,
-                                                    const std::string& instancePublicId) :
-    context_(context),
-    instancePublicId_(instancePublicId)
-  {
-    accessor_.reset(new ParsedDicomCache::Accessor(context_.dicomCache_, instancePublicId));
-    
-    if (!accessor_->IsValid())
-    {
-      accessor_.reset(NULL);
+        if (SerializationToolbox::ParseUnsignedInteger64(pixelDataOffset, metadata))
+        {
+          return DicomDataSource::Execute(*dicomReader_, DicomDataSource::CreateUntilPixelDataRequest(attachment, pixelDataOffset));
+        }
+        else
+        {
+          LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId;
+        }
+      }
 
-      // Throttle to avoid loading several large DICOM files simultaneously (since the ParsedDicomCache is 128MB, loading multiple 50MB files would throw them out directly after loading)
-      largeDicomLocker_.reset(new Semaphore::Locker(context.largeDicomThrottler_));
-      
-      // Release the throttle if loading "small" DICOM files (under
-      // 50MB, which is an arbitrary value)
-      context_.ReadDicomInternal(buffer_, instancePublicId_, largeDicomLocker_, static_cast<size_t>(50) * 1024 * 1024);
-      
-      dicom_.reset(new ParsedDicomFile(buffer_));
-      dicomSize_ = buffer_.size();
-    }
-
-    assert(accessor_.get() != NULL ||
-           dicom_.get() != NULL);
-  }
-
-
-  ServerContext::DicomCacheLocker::~DicomCacheLocker()
-  {
-    if (dicom_.get() != NULL)
-    {
-      try
-      {
-        context_.dicomCache_.Acquire(instancePublicId_, dicom_.release(), dicomSize_);
-      }
-      catch (OrthancException&) // NOLINT(bugprone-empty-catch)
-      {
-      }
+      // Fallback: The pixel data offset is not present or cannot be used, the whole DICOM file must be read
+      return DicomDataSource::Execute(*dicomReader_, DicomDataSource::CreateWholeRequest(attachment));
     }
   }
 
 
-  ParsedDicomFile& ServerContext::DicomCacheLocker::GetDicom() const
+  TranscoderDataSource::Transcoded* ServerContext::ReadTranscodedDicom(const std::string& instancePublicId,
+                                                                       DicomTransferSyntax targetSyntax,
+                                                                       TranscodingSopInstanceUidMode mode,
+                                                                       bool hasLossyQuality,
+                                                                       unsigned int lossyQuality)
   {
-    if (dicom_.get() != NULL)
-    {
-      return *dicom_;
-    }
-    else
-    {
-      assert(accessor_.get() != NULL);
-      return accessor_->GetDicom();
-    }
+    const FileInfo& attachment = LookupDicomForInstance(instancePublicId);
+    return TranscoderDataSource::Execute(*transcoderReader_, TranscoderDataSource::CreateRequest(
+                                           attachment, targetSyntax, mode, hasLossyQuality, lossyQuality));
   }
 
-  const std::string& ServerContext::DicomCacheLocker::GetBuffer()
-  {
-    if (buffer_.size() > 0)
-    {
-      return buffer_;
-    }
-    else
-    {
-      context_.ReadDicom(buffer_, instancePublicId_);
-      return buffer_;
-    }
-  }
-  
+
   void ServerContext::SetStoreMD5ForAttachments(bool storeMD5)
   {
     LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no");
@@ -1655,12 +1657,14 @@
     // TODO Should we use "gzip" instead?
     CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
 
-    StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
-
     assert(attachmentType != FileContentType_Dicom && attachmentType != FileContentType_DicomUntilPixelData); // this method can not be used to store instances
 
     FileInfo attachment;
-    accessor.Write(attachment, data, size, attachmentType, compression, storeMD5_, NULL);
+
+    {
+      StorageAccessor accessor(area_, *metricsRegistry_);
+      accessor.Write(attachment, data, size, attachmentType, compression, storeMD5_, NULL);
+    }
 
     try
     {
@@ -1668,7 +1672,7 @@
         newRevision, attachment, resourceId, hasOldRevision, oldRevision, oldMD5);
       if (status != StoreStatus_Success)
       {
-        accessor.Remove(attachment);
+        RemoveFile(attachment);
         return false;
       }
       else
@@ -1679,7 +1683,7 @@
     catch (OrthancException&)
     {
       // Fixed in Orthanc 1.9.6
-      accessor.Remove(attachment);
+      RemoveFile(attachment);
       throw;
     }
   }
@@ -1689,24 +1693,12 @@
                                      const std::string& uuid,
                                      ResourceType expectedType)
   {
-    if (expectedType == ResourceType_Instance)
-    {
-      // remove the file from the DicomCache
-      dicomCache_.Invalidate(uuid);
-    }
-
     return index_.DeleteResource(remainingAncestor, uuid, expectedType);
   }
 
 
   void ServerContext::SignalChange(const ServerIndexChange& change)
   {
-    if (change.GetResourceType() == ResourceType_Instance &&
-        change.GetChangeType() == ChangeType_Deleted)
-    {
-      dicomCache_.Invalidate(change.GetPublicId());
-    }
-    
     pendingChanges_.Enqueue(change.Clone());
   }
 
@@ -1937,65 +1929,56 @@
   }
 
 
-
-
-
-  ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& publicId,
+  ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& instancePublicId,
                                                  unsigned int frameIndex)
   {
-    ServerContext::DicomCacheLocker locker(*this, publicId);
-    std::unique_ptr<ImageAccessor> decoded(GetTranscoder().DecodeFrame(locker.GetDicom(), locker.GetBuffer().c_str(), locker.GetBuffer().size(), frameIndex));
+    FileInfo attachment;
+    int64_t revision;
+
+    if (!index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom))
+    {
+      throw OrthancException(ErrorCode_InternalError,
+                             "Unable to read attachment " + EnumerationToString(FileContentType_Dicom) +
+                             " of instance " + instancePublicId);
+    }
+
+    std::unique_ptr<ImageAccessor> decoded;
+
+    decoded.reset(GetTranscoder()->DecodeFrame(dicomReader_, storageAreaReader_, transcoderReader_, attachment, frameIndex));
 
     if (decoded.get() == NULL)
     {
       OrthancConfiguration::ReaderLock configLock;
       if (configLock.GetConfiguration().IsWarningEnabled(Warnings_003_DecoderFailure))
       {
-        LOG(WARNING) << "W003: Unable to decode frame " << frameIndex << " from instance " << publicId;
+        LOG(WARNING) << "W003: Unable to decode frame " << frameIndex << " from instance " << instancePublicId;
       }
-      return NULL;
+
+      throw OrthancException(ErrorCode_NotImplemented);
     }
-
-    return decoded.release();
+    else
+    {
+      return decoded.release();
+    }
   }
 
 
-  ImageAccessor* ServerContext::DecodeDicomFrame(const DicomInstanceToStore& dicom,
-                                                 unsigned int frameIndex)
-  {
-    return GetTranscoder().DecodeFrame(dicom.GetParsedDicomFile(),
-                                    dicom.GetBufferData(),
-                                    dicom.GetBufferSize(),
-                                    frameIndex);
-
-  }
-
-
-  ImageAccessor* ServerContext::DecodeDicomFrame(const void* dicom,
-                                                 size_t size,
-                                                 unsigned int frameIndex)
-  {
-    std::unique_ptr<ParsedDicomFile> instance(new ParsedDicomFile(dicom, size));
-    return GetTranscoder().DecodeFrame(*instance, dicom, size, frameIndex);
-  }
-  
-
   void ServerContext::PerformCStoreWithTranscoding(std::string& sopClassUid,
                                                    std::string& sopInstanceUid,
                                                    DicomStoreUserConnection& connection,
-                                                   const std::string& dicom,
+                                                   const void* dicomData,
+                                                   size_t dicomSize,
                                                    bool hasMoveOriginator,
                                                    const std::string& moveOriginatorAet,
                                                    uint16_t moveOriginatorId)
   {
-    const void* data = dicom.empty() ? NULL : dicom.c_str();
     const RemoteModalityParameters& modality = connection.GetParameters().GetRemoteModality();
 
     // Filter out outgoing C-Store instances
     {
       boost::shared_lock<boost::shared_mutex> lock(listenersMutex_);
 
-      std::unique_ptr<OutgoingDicomInstance> outgoingInstance(OutgoingDicomInstance::CreateFromBuffer(dicom));
+      std::unique_ptr<OutgoingDicomInstance> outgoingInstance(OutgoingDicomInstance::CreateFromBuffer(dicomData, dicomSize));
       outgoingInstance->SetDestination(DicomInstanceDestination(connection.GetParameters().GetRemoteModality().GetHost(),
                                                                 connection.GetParameters().GetRemoteModality().GetApplicationEntityTitle()));
 
@@ -2024,48 +2007,17 @@
     if (!transcodeDicomProtocol_ ||
         !modality.IsTranscodingAllowed())
     {
-      connection.Store(sopClassUid, sopInstanceUid, data, dicom.size(),
+      connection.Store(sopClassUid, sopInstanceUid, dicomData, dicomSize,
                        hasMoveOriginator, moveOriginatorAet, moveOriginatorId);
     }
     else
     {
-      connection.Transcode(sopClassUid, sopInstanceUid, *transcoder_, data, dicom.size(), preferredTransferSyntax_,
+      connection.Transcode(sopClassUid, sopInstanceUid, *transcoder_, dicomData, dicomSize, preferredTransferSyntax_,
                            hasMoveOriginator, moveOriginatorAet, moveOriginatorId);
     }
   }
 
 
-  bool ServerContext::TranscodeWithCache(std::string& target,
-                                         const std::string& source,
-                                         const std::string& sourceInstanceId,
-                                         const std::string& attachmentId,
-                                         DicomTransferSyntax targetSyntax)
-  {
-    StorageCache::Accessor cacheAccessor(storageCache_);
-
-    if (!cacheAccessor.FetchTranscodedInstance(target, attachmentId, targetSyntax))
-    {
-      IDicomTranscoder::DicomImage sourceDicom;
-      sourceDicom.SetExternalBuffer(source);
-
-      IDicomTranscoder::DicomImage targetDicom;
-      std::set<DicomTransferSyntax> syntaxes;
-      syntaxes.insert(targetSyntax);
-
-      if (GetTranscoder().Transcode(targetDicom, sourceDicom, syntaxes, TranscodingSopInstanceUidMode_AllowNew))
-      {
-        cacheAccessor.AddTranscodedInstance(attachmentId, targetSyntax, reinterpret_cast<const char*>(targetDicom.GetBufferData()), targetDicom.GetBufferSize());
-        target = std::string(reinterpret_cast<const char*>(targetDicom.GetBufferData()), targetDicom.GetBufferSize());
-        return true;
-      }
-
-      return false;
-    }
-
-    return true;
-  }
-
-
   const std::string& ServerContext::GetDeidentifiedContent(const DicomElement &element) const
   {
     static const std::string redactedContent = "*** POTENTIAL PHI ***";
@@ -2254,47 +2206,21 @@
   }
 
 
-  void ServerContext::SetTranscoder(ServerTranscoder* transcoder)
+  const boost::shared_ptr<ServerTranscoder>& ServerContext::GetTranscoder() const
   {
-    std::unique_ptr<ServerTranscoder> protection(transcoder);
-
-    if (transcoder == NULL)
+    if (transcoder_.get() != NULL)
     {
-      throw OrthancException(ErrorCode_NullPointer);
-    }
-    else if (transcoder_.get() != NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      return transcoder_;
     }
     else
     {
-      transcoder_.reset(protection.release());
+      throw OrthancException(ErrorCode_BadSequenceOfCalls, "No transcoder is available");
     }
   }
 
 
-  ServerTranscoder& ServerContext::GetTranscoder() const
+  DicomSequentialReader::Factory& ServerContext::GetDicomSequentialReaderFactory()
   {
-    if (transcoder_.get() != NULL)
-    {
-      return *transcoder_;
-    }
-    else
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-  }
-
-
-  void ServerContext::ResetTranscoder()
-  {
-    if (transcoder_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      transcoder_.reset(NULL);
-    }
+    return *dicomSequentialReaderFactory_;
   }
 }
--- a/OrthancServer/Sources/ServerContext.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Tue Jun 02 07:41:56 2026 +0200
@@ -28,13 +28,15 @@
 #include "OrthancHttpHandler.h"
 #include "ServerIndex.h"
 #include "ServerJobs/IStorageCommitmentFactory.h"
-#include "ServerTranscoder.h"
 
+#include "../../OrthancFramework/Sources/DataSource/DicomDataSource.h"
+#include "../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h"
+#include "../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h"
+#include "../../OrthancFramework/Sources/DataSource/TranscoderDataSource.h"
 #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h"
-#include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomCache.h"
-#include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
-#include "../../OrthancFramework/Sources/FileStorage/StorageCache.h"
 #include "../../OrthancFramework/Sources/JobsEngine/JobsEngine.h"
+#include "../../OrthancFramework/Sources/MetricsRegistry.h"
+#include "../../OrthancFramework/Sources/MultiThreading/Future.h"
 #include "../../OrthancFramework/Sources/MultiThreading/Semaphore.h"
 
 
@@ -42,11 +44,13 @@
 {
   class DicomElement;
   class DicomStoreUserConnection;
+  class IExecutorService;
   class OrthancPlugins;
+  class ServerTranscoder;
   class SharedArchive;
   class StorageCommitmentReports;
   
-  
+
   /**
    * This class is responsible for maintaining the storage area on the
    * filesystem (including compression), as well as the index of the
@@ -192,13 +196,11 @@
 
     ServerIndex index_;
     IPluginStorageArea& area_;
-    StorageCache storageCache_;
 
     bool compressionEnabled_;
     bool storeMD5_;
 
     Semaphore largeDicomThrottler_;  // New in Orthanc 1.9.0 (notably for very large DICOM files in WSI)
-    ParsedDicomCache  dicomCache_;
 
     LuaScripting mainLua_;
     LuaScripting filterLua_;
@@ -238,7 +240,7 @@
     unsigned int limitFindInstances_;
     unsigned int limitFindResults_;
 
-    std::unique_ptr<MetricsRegistry>  metricsRegistry_;
+    boost::shared_ptr<MetricsRegistry>  metricsRegistry_;
     bool isHttpServerSecure_;
     bool isExecuteLuaEnabled_;
     bool isRestApiWriteToFileSystemEnabled_;
@@ -246,7 +248,7 @@
 
     std::unique_ptr<StorageCommitmentReports>  storageCommitmentReports_;
 
-    std::unique_ptr<ServerTranscoder> transcoder_;
+    boost::shared_ptr<ServerTranscoder> transcoder_;
     bool transcodeDicomProtocol_;
     bool isIngestTranscoding_;
     DicomTransferSyntax ingestTransferSyntax_;
@@ -277,6 +279,8 @@
                     FileContentType type,
                     const std::string& customData);
 
+    void RemoveFile(const FileInfo& attachment);
+
     // This DicomModification object is intended to be used as a
     // "rules engine" when de-identifying logs for C-Find, C-Get, and
     // C-Move queries (new in Orthanc 1.8.2)
@@ -285,31 +289,16 @@
 
     boost::posix_time::ptime serverStartTimeUtc_;
 
-  public:
-    class DicomCacheLocker : public boost::noncopyable
-    {
-    private:
-      ServerContext&                               context_;
-      std::string                                  instancePublicId_;
-      std::unique_ptr<ParsedDicomCache::Accessor>  accessor_;
-      std::unique_ptr<ParsedDicomFile>             dicom_;
-      size_t                                       dicomSize_;
-      std::unique_ptr<Semaphore::Locker>           largeDicomLocker_;
-      std::string                                  buffer_;
+    // For streaming
+    boost::shared_ptr<DataSourceReader>                storageAreaReader_;
+    boost::shared_ptr<DataSourceReader>                dicomReader_;
+    boost::shared_ptr<DataSourceReader>                transcoderReader_;
+    boost::shared_ptr<DicomSequentialReader::Factory>  dicomSequentialReaderFactory_;
 
-    public:
-      DicomCacheLocker(ServerContext& context,
-                       const std::string& instancePublicId);
-
-      ~DicomCacheLocker();
-
-      ParsedDicomFile& GetDicom() const;
-
-      const std::string& GetBuffer();
-    };
-
+  public:
     ServerContext(IDatabaseWrapper& database,
                   IPluginStorageArea& area,
+                  ServerTranscoder* transcoder /* takes ownership */,
                   bool unitTesting,
                   size_t maxCompletedJobs,
                   bool readOnly);
@@ -326,7 +315,7 @@
 
     void SetMaximumStorageCacheSize(size_t size)
     {
-      return storageCache_.SetMaximumSize(size);
+      // TODO-Streaming
     }
 
     void SetPatientLevelEnabled(bool enabled);
@@ -371,7 +360,7 @@
 
     StoreResult TranscodeAndStore(std::string& resultPublicId,
                                   DicomInstanceToStore* dicom,
-                                  bool isReconstruct = false);
+                                  bool isReconstruct = false);  // TODO-Streaming: To check
 
     void AnswerAttachment(RestApiOutput& output,
                           const FileInfo& fileInfo,
@@ -395,42 +384,26 @@
     void ReadDicomAsJson(Json::Value& result,
                          const std::string& instancePublicId);  // TODO-FIND: Can this be removed?
 
-private:
-    void ReadDicomInternal(std::string& dicom,
-                           const std::string& instancePublicId,
-                           std::unique_ptr<Semaphore::Locker>& largeDicomLocker,
-                           std::size_t largeDicomThreshold);
+    FileInfo LookupDicomForInstance(const std::string& instancePublicId);
 
-    void ReadDicomInternal(std::string& dicom,
-                           std::string& attachmentId,
-                           const std::string& instancePublicId,
-                           std::unique_ptr<Semaphore::Locker>& largeDicomLocker,
-                           std::size_t largeDicomThreshold);
+    StorageAreaDataSource::Range* ReadAttachment(const FileInfo& attachment,
+                                                 bool uncompress);
 
-public:
-    void ReadDicom(std::string& dicom,
-                   const std::string& instancePublicId);
+    StorageAreaDataSource::Range* ReadAttachment(const FileInfo& attachment,
+                                                 const StorageRange& range,
+                                                 bool uncompress);
 
-    void ReadDicom(std::string& dicom,
-                   std::string& attachmentId,
-                   const std::string& instancePublicId);
+    StorageAreaDataSource::Range* ReadRawDicom(const std::string& instancePublicId);
 
-    void ReadDicomForHeader(std::string& dicom,
-                            const std::string& instancePublicId);
+    DicomDataSource::Dicom* ReadParsedDicom(const std::string& instancePublicId);
 
-    bool ReadDicomUntilPixelData(std::string& dicom,
-                                 const std::string& instancePublicId);
+    DicomDataSource::Dicom* ReadDicomUntilPixelData(const std::string& instancePublicId);
 
-    // This method is for low-level operations on "/instances/.../attachments/..."
-    void ReadAttachment(std::string& result,
-                        const FileInfo& attachment,
-                        bool uncompressIfNeeded,
-                        bool skipCache = false);
-
-    void ReadAttachmentRange(std::string& result,
-                             const FileInfo& attachment,
-                             const StorageRange& range,
-                             bool uncompressIfNeeded);
+    TranscoderDataSource::Transcoded* ReadTranscodedDicom(const std::string& instancePublicId,
+                                                          DicomTransferSyntax targetSyntax,
+                                                          TranscodingSopInstanceUidMode mode,
+                                                          bool hasLossyQuality,
+                                                          unsigned int lossyQuality);
 
     void SetStoreMD5ForAttachments(bool storeMD5);
 
@@ -583,27 +556,15 @@
     ImageAccessor* DecodeDicomFrame(const std::string& publicId,
                                     unsigned int frameIndex);
 
-    ImageAccessor* DecodeDicomFrame(const DicomInstanceToStore& dicom,
-                                    unsigned int frameIndex);
-
-    ImageAccessor* DecodeDicomFrame(const void* dicom,
-                                    size_t size,
-                                    unsigned int frameIndex);
-
     void PerformCStoreWithTranscoding(std::string& sopClassUid,
                                       std::string& sopInstanceUid,
                                       DicomStoreUserConnection& connection,
-                                      const std::string& dicom,
+                                      const void* dicomData,
+                                      size_t dicomSize,
                                       bool hasMoveOriginator,
                                       const std::string& moveOriginatorAet,
                                       uint16_t moveOriginatorId);
 
-    virtual bool TranscodeWithCache(std::string& target,
-                                    const std::string& source,
-                                    const std::string& sourceInstanceId,
-                                    const std::string& attachmentId, // for the storage cache
-                                    DicomTransferSyntax targetSyntax);
-
     bool IsTranscodeDicomProtocol() const
     {
       return transcodeDicomProtocol_;
@@ -633,12 +594,8 @@
 
     int64_t GetServerUpTime() const;
 
-    void PublishCacheMetrics();
-
-    void SetTranscoder(ServerTranscoder* transcoder /* takes ownership */);
+    const boost::shared_ptr<ServerTranscoder>& GetTranscoder() const;
 
-    ServerTranscoder& GetTranscoder() const;
-
-    void ResetTranscoder();
+    DicomSequentialReader::Factory& GetDicomSequentialReaderFactory();
   };
 }
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -27,6 +27,7 @@
 #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h"
 #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h"
 #include "../../../OrthancFramework/Sources/Constants.h"
+#include "../../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../../OrthancFramework/Sources/Logging.h"
@@ -37,7 +38,6 @@
 #include "../OrthancConfiguration.h"
 #include "../ServerContext.h"
 #include "../SimpleInstanceOrdering.h"
-#include "ThreadedInstancesLoader.h"
 
 #include <cassert>
 #include <stdio.h>
@@ -476,12 +476,12 @@
     {
     }
 
-    virtual void Preload(ThreadedInstancesLoader& instancesLoader) const = 0;
+    virtual void Preload(DicomSequentialReader& instancesLoader) const = 0;
 
     // In the "archive" flavor (without DICOMDIR), dicomDir is NULL
     // In the "media" flavor (with DICOMDIR), dicomDir is not NULL
     virtual void Execute(HierarchicalZipWriter& writer,
-                         ThreadedInstancesLoader& instancesLoader,
+                         DicomSequentialReader& instancesLoader,
                          DicomDirWriter* dicomDir) const = 0;
   };
 
@@ -495,17 +495,17 @@
       std::string   filename_;
 
     public:
-      OpenDirectoryCommand(const std::string& filename) :
+      explicit OpenDirectoryCommand(const std::string& filename) :
         filename_(filename)
       {
       }
 
-      virtual void Preload(ThreadedInstancesLoader& instancesLoader) const ORTHANC_OVERRIDE
+      virtual void Preload(DicomSequentialReader& instancesLoader) const ORTHANC_OVERRIDE
       {
       }
 
       virtual void Execute(HierarchicalZipWriter& writer,
-                           ThreadedInstancesLoader& instancesLoader,
+                           DicomSequentialReader& instancesLoader,
                            DicomDirWriter* dicomDir) const ORTHANC_OVERRIDE
       {
         writer.OpenDirectory(filename_);
@@ -516,12 +516,12 @@
     class CloseDirectoryCommand : public IZipCommand
     {
     public:
-      virtual void Preload(ThreadedInstancesLoader& instancesLoader) const ORTHANC_OVERRIDE
+      virtual void Preload(DicomSequentialReader& instancesLoader) const ORTHANC_OVERRIDE
       {
       }
 
       virtual void Execute(HierarchicalZipWriter& writer,
-                           ThreadedInstancesLoader& instancesLoader,
+                           DicomSequentialReader& instancesLoader,
                            DicomDirWriter* dicomDir) const ORTHANC_OVERRIDE
       {
         writer.CloseDirectory();
@@ -551,36 +551,43 @@
                dicomDirFolder == MEDIA_IMAGES_FOLDER);
       }
 
-      virtual void Preload(ThreadedInstancesLoader& instancesLoader) const ORTHANC_OVERRIDE
+      virtual void Preload(DicomSequentialReader& instancesLoader) const ORTHANC_OVERRIDE
       {
-        instancesLoader.PreloadDicomInstance(instanceId_, fileInfo_);
+        instancesLoader.Submit(fileInfo_);
       }
 
       virtual void Execute(HierarchicalZipWriter& writer,
-                           ThreadedInstancesLoader& instancesLoader,
+                           DicomSequentialReader& instancesLoader,
                            DicomDirWriter* dicomDir) const ORTHANC_OVERRIDE
       {
-        std::string content;
-
-        try
+        if (!instancesLoader.HasNext())
         {
-          LOG(INFO) << "Adding instance " << instanceId_ << " in zip";
-          instancesLoader.WaitDicomInstance(content, instanceId_);
+          throw OrthancException(ErrorCode_InternalError);
         }
-        catch (OrthancException& e)
+        else
         {
-          LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_;
-          return;
-        }
-
-        writer.OpenFile(filename_);
+          std::unique_ptr<DicomSequentialReader::Item> next;
 
-        writer.Write(content);
+          try
+          {
+            LOG(INFO) << "Adding instance " << instanceId_ << " in zip";
+            next.reset(instancesLoader.Next());
+          }
+          catch (OrthancException& e)
+          {
+            LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_;
+            return;
+          }
 
-        if (dicomDir != NULL)
-        {
-          std::unique_ptr<ParsedDicomFile> parsed(new ParsedDicomFile(content));
-          dicomDir->Add(dicomDirFolder_, filename_, *parsed);
+          const IMemoryBuffer& dicom = next->GetRawMemoryBuffer();
+
+          writer.OpenFile(filename_);
+          writer.Write(dicom.GetData(), dicom.GetSize());
+
+          if (dicomDir != NULL)
+          {
+            dicomDir->Add(dicomDirFolder_, filename_, next->GetParsedDicomFile());
+          }
         }
       }
     };
@@ -932,7 +939,7 @@
       return commands_.GetSize() + 1;
     }
 
-    void PreloadAllCommands(ThreadedInstancesLoader& instancesLoader)
+    void PreloadAllCommands(DicomSequentialReader& instancesLoader)
     {
       for (size_t i = 0; i < commands_.GetSize(); i++)
       {
@@ -940,7 +947,7 @@
       }
     }
 
-    void RunStep(ThreadedInstancesLoader& instancesLoader,
+    void RunStep(DicomSequentialReader& instancesLoader,
                  size_t index)
     {
       if (index > commands_.GetSize())
@@ -1194,8 +1201,19 @@
       instancesCount_ = writer_->GetInstancesCount();
       uncompressedSize_ = writer_->GetUncompressedSize();
 
-      instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads_, transcode_, transferSyntax_, lossyQuality_, "ARCH"));
+      if (transcode_)
+      {
+        instancesLoader_.reset(context_.GetDicomSequentialReaderFactory().CreateForTranscodedRawMemoryBuffer(
+                                 transferSyntax_, TranscodingSopInstanceUidMode_AllowNew, hasLossyQuality_, lossyQuality_));
+      }
+      else
+      {
+        instancesLoader_.reset(context_.GetDicomSequentialReaderFactory().CreateForOriginalRawMemoryBuffer());
+      }
+
       writer_->PreloadAllCommands(*instancesLoader_);
+
+      instancesLoader_->Start();
     }
   }
 
@@ -1235,10 +1253,7 @@
       writer_.reset();
     }
 
-    if (instancesLoader_.get() != NULL)
-    {
-      instancesLoader_->Clear(false);
-    }
+    instancesLoader_.reset(NULL);
 
     if (asynchronousTarget_.get() != NULL)
     {
@@ -1307,10 +1322,7 @@
       asynchronousTarget_.reset();
 
       // clear the loader threads
-      if (instancesLoader_.get() != NULL)
-      {
-        instancesLoader_->Clear(true);
-      }
+      instancesLoader_.reset(NULL);
     }
   }
 
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h	Tue Jun 02 07:41:56 2026 +0200
@@ -33,9 +33,9 @@
 
 namespace Orthanc
 {
+  class DicomSequentialReader;
   class ServerContext;
-  class ThreadedInstancesLoader;
-  
+
   class ArchiveJob : public IJob
   {
   private:
@@ -51,7 +51,7 @@
     std::unique_ptr<ZipWriter::IOutputStream>  synchronousTarget_;  // Only valid before "Start()"
     std::unique_ptr<TemporaryFile>        asynchronousTarget_;
     ServerContext&                        context_;
-    std::unique_ptr<ThreadedInstancesLoader>  instancesLoader_;
+    std::unique_ptr<DicomSequentialReader>  instancesLoader_;
     boost::shared_ptr<ArchiveIndex>       archive_;
     bool                                  isMedia_;
     bool                                  enableExtendedSopClass_;
--- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -48,19 +48,14 @@
     assert(IsStarted());
     OpenConnection();
 
-    if (instancesLoader_.get() == NULL)
-    {
-      StartLoaderThreads();
-    }
-
     LOG(INFO) << "Sending instance " << instance << " to modality \"" 
               << parameters_.GetRemoteModality().GetApplicationEntityTitle() << "\"";
 
-    std::string dicom;
+    std::unique_ptr<DicomSequentialReader::Item> item;
 
     try
     {
-      instancesLoader_->WaitDicomInstance(dicom, instance);
+      item.reset(WaitDicomInstance(instance));
     }
     catch (OrthancException& e)
     {
@@ -68,8 +63,10 @@
       return false;
     }
 
+    const IMemoryBuffer& dicom = item->GetRawMemoryBuffer();
+
     std::string sopClassUid, sopInstanceUid;
-    context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, *connection_, dicom,
+    context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, *connection_, dicom.GetData(), dicom.GetSize(),
                                           HasMoveOriginator(), moveOriginatorAet_, moveOriginatorId_);
 
     if (storageCommitment_)
--- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h	Tue Jun 02 07:41:56 2026 +0200
@@ -56,11 +56,6 @@
     
     virtual bool HandleTrailingStep() ORTHANC_OVERRIDE;
 
-    virtual const char* GetLoaderPrefix() const ORTHANC_OVERRIDE
-    {
-      return "CSTO";
-    }
-
   public:
     explicit DicomModalityStoreJob(ServerContext& context);
 
--- a/OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -97,8 +97,8 @@
 
     try
     {
-      ServerContext::DicomCacheLocker locker(GetContext(), instance);
-      modified.reset(locker.GetDicom().Clone(true));
+      std::unique_ptr<DicomDataSource::Dicom> dicom(GetContext().ReadParsedDicom(instance));
+      modified.reset(dicom->Clone());
     }
     catch (OrthancException&)
     {
@@ -201,8 +201,10 @@
     DicomMap dicom;
 
     {
-      ServerContext::DicomCacheLocker locker(GetContext(), instances.front());
-      OrthancConfiguration::DefaultExtractDicomSummary(dicom, locker.GetDicom());
+      std::unique_ptr<DicomDataSource::Dicom> loadedDicom(GetContext().ReadParsedDicom(instances.front()));
+      DicomDataSource::Dicom::Lock lock(*loadedDicom);
+
+      OrthancConfiguration::DefaultExtractDicomSummary(dicom, lock.GetContent());
     }
 
     const std::set<DicomTag> moduleTags = removals_;
--- a/OrthancServer/Sources/ServerJobs/Operations/DicomInstanceOperationValue.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/Operations/DicomInstanceOperationValue.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -30,6 +30,7 @@
 {
   void DicomInstanceOperationValue::ReadDicom(std::string& dicom) const
   {
-    context_.ReadDicom(dicom, id_);
+    std::unique_ptr<StorageAreaDataSource::Range> raw(context_.ReadRawDicom(id_));
+    raw->Copy(dicom);
   }
 }
--- a/OrthancServer/Sources/ServerJobs/Operations/ModifyInstanceOperation.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/Operations/ModifyInstanceOperation.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -87,8 +87,8 @@
     std::unique_ptr<ParsedDicomFile> modified;
     
     {
-      ServerContext::DicomCacheLocker lock(context_, instance.GetId());
-      modified.reset(lock.GetDicom().Clone(true));
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context_.ReadParsedDicom(instance.GetId()));
+      modified.reset(dicom->Clone());
     }
 
     try
--- a/OrthancServer/Sources/ServerJobs/Operations/StoreScuOperation.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/Operations/StoreScuOperation.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -55,7 +55,8 @@
       instance.ReadDicom(dicom);
 
       std::string sopClassUid, sopInstanceUid;  // Unused
-      context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, lock.GetConnection(), dicom,
+      context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, lock.GetConnection(),
+                                            dicom.empty() ? NULL : dicom.c_str(), dicom.size(),
                                             false /* Not a C-MOVE */, "", 0);
     }
     catch (OrthancException& e)
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -29,6 +29,7 @@
 #include "../../../OrthancFramework/Sources/Logging.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
 #include "../ServerContext.h"
+#include "../ServerTranscoder.h"
 
 #include <dcmtk/dcmdata/dcfilefo.h>
 
@@ -37,10 +38,7 @@
 {
   bool OrthancPeerStoreJob::HandleInstance(const std::string& instance)
   {
-    if (instancesLoader_.get() == NULL)
-    {
-      StartLoaderThreads();
-    }
+    assert(IsStarted());
 
     if (client_.get() == NULL)
     {
@@ -62,8 +60,10 @@
 
     try
     {
-      std::string dicom;
-      instancesLoader_->WaitDicomInstance(dicom, instance);
+      std::unique_ptr<DicomSequentialReader::Item> item;
+      item.reset(WaitDicomInstance(instance));
+
+      const IMemoryBuffer& dicom = item->GetRawMemoryBuffer();
 
       if (transcode_)
       {
@@ -71,21 +71,21 @@
         syntaxes.insert(transferSyntax_);
         
         IDicomTranscoder::DicomImage source, transcoded;
-        source.SetExternalBuffer(dicom);
+        source.SetExternalBuffer(dicom.GetData(), dicom.GetSize());
 
-        if (context_.GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew))
+        if (context_.GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew))
         {
           body.assign(reinterpret_cast<const char*>(transcoded.GetBufferData()),
                       transcoded.GetBufferSize());
         }
         else
         {
-          body.swap(dicom);
+          dicom.CopyToString(body);
         }
       }
       else
       {
-        body.swap(dicom);
+        dicom.CopyToString(body);
       }
     }
     catch (OrthancException& e)
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h	Tue Jun 02 07:41:56 2026 +0200
@@ -49,11 +49,6 @@
     
     virtual bool HandleTrailingStep() ORTHANC_OVERRIDE;
 
-    virtual const char* GetLoaderPrefix() const ORTHANC_OVERRIDE
-    {
-      return "PSTO";
-    }
-
   public:
     explicit OrthancPeerStoreJob(ServerContext& context) :
       StoreJob(context),
--- a/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -24,10 +24,12 @@
 #include "../PrecompiledHeadersServer.h"
 #include "ResourceModificationJob.h"
 
+#include "../../../OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h"
 #include "../../../OrthancFramework/Sources/Logging.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
 #include "../DicomInstanceToStore.h"
 #include "../ServerContext.h"
+#include "../ServerTranscoder.h"
 
 #include <dcmtk/dcmdata/dcfilefo.h>
 #include <dcmtk/dcmdata/dcdeftag.h>
@@ -185,8 +187,10 @@
     {
       for (std::set<std::string>::const_iterator it = instancesToReconstruct_.begin(); it != instancesToReconstruct_.end(); ++it)
       {
-        ServerContext::DicomCacheLocker locker(GetContext(), *it);
-        const ParsedDicomFile& modifiedDicom = locker.GetDicom();
+        std::unique_ptr<DicomDataSource::Dicom> dicom(GetContext().ReadParsedDicom(*it));
+        DicomDataSource::Dicom::Lock dicomLock(*dicom);
+
+        const ParsedDicomFile& modifiedDicom = dicomLock.GetContent();
 
         GetContext().GetIndex().ReconstructInstance(modifiedDicom, false, ResourceType_Instance /* dummy */);
       }
@@ -219,8 +223,10 @@
  
     try
     {
-      ServerContext::DicomCacheLocker locker(GetContext(), instance);
-      const ParsedDicomFile& original = locker.GetDicom();
+      std::unique_ptr<DicomDataSource::Dicom> dicom(GetContext().ReadParsedDicom(instance));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+
+      const ParsedDicomFile& original = lock.GetContent();
 
       originalHasher.reset(new DicomInstanceHasher(original.GetHasher()));
       modified.reset(original.Clone(true));
@@ -262,7 +268,7 @@
       source.AcquireParsed(*modified);  // "modified" is invalid below this point
       
       IDicomTranscoder::DicomImage transcoded;
-      if (GetContext().GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew))
+      if (GetContext().GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew))
       {
         modified.reset(transcoded.ReleaseAsParsedDicomFile());
 
--- a/OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -72,8 +72,8 @@
 
     try
     {
-      ServerContext::DicomCacheLocker locker(GetContext(), instance);
-      modified.reset(locker.GetDicom().Clone(true));
+      std::unique_ptr<DicomDataSource::Dicom> dicom(GetContext().ReadParsedDicom(instance));
+      modified.reset(dicom->Clone());
     }
     catch (OrthancException&)
     {
--- a/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -290,9 +290,12 @@
           // Make sure that the DICOM file can be re-read by DCMTK
           // from the file storage, and that the actual SOP
           // class/instance UIDs do match
-          ServerContext::DicomCacheLocker locker(context_, orthancId[0]);
-          if (locker.GetDicom().GetTagValue(a, DICOM_TAG_SOP_CLASS_UID) &&
-              locker.GetDicom().GetTagValue(b, DICOM_TAG_SOP_INSTANCE_UID) &&
+
+          std::unique_ptr<DicomDataSource::Dicom> dicom(context_.ReadParsedDicom(orthancId[0]));
+          DicomDataSource::Dicom::Lock lock(*dicom);
+
+          if (lock.GetContent().GetTagValue(a, DICOM_TAG_SOP_CLASS_UID) &&
+              lock.GetContent().GetTagValue(b, DICOM_TAG_SOP_INSTANCE_UID) &&
               b == sopInstanceUids_[index])
           {
             if (a == sopClassUids_[index])
--- a/OrthancServer/Sources/ServerJobs/StoreJob.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/StoreJob.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -35,6 +35,24 @@
 
 namespace Orthanc
 {
+  class StoreJob::ReaderUserData : public IDynamicObject
+  {
+  private:
+    std::string instanceId_;
+
+  public:
+    explicit ReaderUserData(const std::string& instanceId) :
+      instanceId_(instanceId)
+    {
+    }
+
+    const std::string& GetInstanceId() const
+    {
+      return instanceId_;
+    }
+  };
+
+
   StoreJob::StoreJob(ServerContext& context) :
     context_(context)
   {
@@ -63,6 +81,51 @@
   }
 
 
+  DicomSequentialReader::Item* StoreJob::WaitDicomInstance(const std::string& instanceId)
+  {
+    assert(IsStarted());
+
+    if (instancesLoader_.get() == NULL)
+    {
+      instancesLoader_.reset(context_.GetDicomSequentialReaderFactory().CreateForOriginalRawMemoryBuffer());
+
+      const size_t position = GetPosition(); // in case we reload a job in progress, we shall not preload the first instances
+
+      if (instanceId != instancesIds_[position])
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+
+      for (size_t i = position; i < instancesIds_.size(); ++i)
+      {
+        instancesLoader_->Submit(filesInfo_[i], new ReaderUserData(instancesIds_[i]));
+      }
+
+      instancesLoader_->Start();
+    }
+
+    if (!instancesLoader_->HasNext())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+
+    std::unique_ptr<DicomSequentialReader::Item> next(instancesLoader_->Next());
+    assert(next.get() != NULL &&
+           next->HasUserData());
+
+    {
+      // This is just a sanity check, the class "MoveReaderUserData" could be removed
+      const ReaderUserData& userData = dynamic_cast<const ReaderUserData&>(next->GetUserData());
+      if (userData.GetInstanceId() != instanceId)
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+
+    return next.release();
+  }
+
+
   void StoreJob::AddInstances(const std::vector<std::string>& instancesIds,
                               const std::vector<FileInfo>& filesInfo)
   {
@@ -81,24 +144,6 @@
     }
   }
 
-
-  void StoreJob::StartLoaderThreads()
-  {
-    size_t loaderThreads = 1;
-    {
-      OrthancConfiguration::ReaderLock lock;
-      loaderThreads = lock.GetConfiguration().GetLoaderThreads();
-    }
-
-    instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads, false, DicomTransferSyntax_LittleEndianImplicit /* dummy value not used*/, 0, GetLoaderPrefix()));
-
-    size_t position = GetPosition(); // in case we reload a job in progress, we shall not preload the first instances
-    for (size_t i = position; i < instancesIds_.size(); ++i)
-    {
-      instancesLoader_->PreloadDicomInstance(instancesIds_[i], filesInfo_[i]);
-    }
-  }
-
   
   void StoreJob::Stop(JobStopReason reason)
   {
--- a/OrthancServer/Sources/ServerJobs/StoreJob.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/StoreJob.h	Tue Jun 02 07:41:56 2026 +0200
@@ -24,27 +24,30 @@
 #pragma once
 
 #include "../../../OrthancFramework/Sources/Compatibility.h"
-#include "../../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h"
+#include "../../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h"
 #include "../../../OrthancFramework/Sources/FileStorage/FileInfo.h"
-#include "ThreadedInstancesLoader.h"
+#include "../../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h"
 
 #include <vector>
 
 namespace Orthanc
 {
+  class DicomSequentialReader;
   class ServerContext;
 
   class StoreJob : public SetOfInstancesJob
   {
+  private:
+    class ReaderUserData;
+
+    std::unique_ptr<DicomSequentialReader>  instancesLoader_;
+    std::vector<std::string>                instancesIds_;
+    std::vector<FileInfo>                   filesInfo_;
+
   protected:
-    ServerContext&                             context_;
-    std::unique_ptr<ThreadedInstancesLoader>   instancesLoader_;
-    std::vector<std::string>                   instancesIds_;
-    std::vector<FileInfo>                      filesInfo_;
+    ServerContext&  context_;
 
-    virtual const char* GetLoaderPrefix() const = 0;
-
-    void StartLoaderThreads();
+    DicomSequentialReader::Item* WaitDicomInstance(const std::string& instanceId);
 
   public:
     explicit StoreJob(ServerContext& context);
--- a/OrthancServer/Sources/ServerJobs/ThreadedInstancesLoader.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,276 +0,0 @@
-/**
- * Orthanc - A Lightweight, RESTful DICOM Store
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#include "ThreadedInstancesLoader.h"
-
-#include "../ServerContext.h"
-#include "../../../OrthancFramework/Sources/Logging.h"
-#include "../../../OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h"
-#include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
-
-static boost::mutex loaderThreadsCounterMutex;
-static uint32_t loaderThreadsCounter = 0;
-
-static std::string GetLoaderThreadName(const std::string& prefix)
-{
-  boost::mutex::scoped_lock lock(loaderThreadsCounterMutex);
-  std::string threadName = prefix + std::string("-LOAD-") +
-                                boost::lexical_cast<std::string>(loaderThreadsCounter++);
-  loaderThreadsCounter %= 1000000;
-
-  return threadName;
-}
-
-namespace Orthanc
-{
-  class InstanceToPreload : public Orthanc::IDynamicObject
-  {
-  private:
-    std::string id_;
-    FileInfo    fileInfo_;
-
-  public:
-    InstanceToPreload(const std::string& id,
-                      const FileInfo& fileInfo) :
-      id_(id),
-      fileInfo_(fileInfo)
-    {
-    }
-
-    const std::string& GetId() const
-    {
-      return id_;
-    }
-
-    const FileInfo& GetFileInfo() const
-    {
-      return fileInfo_;
-    }
-  };
-
-
-  ThreadedInstancesLoader::ThreadedInstancesLoader(ServerContext& context,
-                                                   size_t threadCount,
-                                                   bool transcode,
-                                                   DicomTransferSyntax transferSyntax,
-                                                   unsigned int lossyQuality,
-                                                   const std::string& nameForLogs4Char) :
-    context_(context),
-    transcode_(transcode),
-    transferSyntax_(transferSyntax),
-    lossyQuality_(lossyQuality),
-    nameForLogs4Char_(nameForLogs4Char),
-    availableInstancesSemaphore_(3 * threadCount),
-    instancesToPreload_(0), // no limit on the message queue, the flow control is performed by the availableInstancesSemaphore_
-    loadersShouldStop_(false)
-  {
-    assert(nameForLogs4Char_.size() <= 4);
-
-    if (threadCount < 1)
-    {
-      throw OrthancException(ErrorCode_InternalError);
-    }
-
-    for (size_t i = 0; i < threadCount; i++)
-    {
-      threads_.push_back(new boost::thread(PreloaderWorkerThread, this));
-    }
-  }
-
-
-  ThreadedInstancesLoader::~ThreadedInstancesLoader()
-  {
-    try
-    {
-      ThreadedInstancesLoader::Clear(false);
-    }
-    catch (const OrthancException& e)
-    {
-      // Don't throw exceptions in destructors
-      LOG(ERROR) << "Exception: " << e.What();
-    }
-  }
-
-
-  void ThreadedInstancesLoader::Clear(bool isAbort)
-  {
-    if (threads_.size() > 0)
-    {
-      loadersShouldStop_ = true; // no need to protect this by a mutex. This is the only "writer" and all loaders are "readers"
-
-      if (isAbort)
-      {
-        LOG(INFO) << "Cancelling the loader threads";
-        instancesToPreload_.Clear();
-      }
-      else
-      {
-        LOG(INFO) << "Waiting for loader threads to complete";
-      }
-
-      // unlock the loaders if they are waiting on this message queue (this happens when the job completes sucessfully)
-      for (size_t i = 0; i < threads_.size(); i++)
-      {
-        instancesToPreload_.Enqueue(NULL);
-      }
-
-      // unlock the loaders if they are waiting for room in the availableInstances (this happens when the job is interrupted)
-      availableInstancesSemaphore_.Release(threads_.size());
-
-      for (size_t i = 0; i < threads_.size(); i++)
-      {
-        if (threads_[i]->joinable())
-        {
-          threads_[i]->join();
-        }
-        delete threads_[i];
-      }
-
-      threads_.clear();
-      availableInstances_.clear();
-
-      LOG(INFO) << "Waiting for loader threads to complete - done";
-    }
-  }
-
-
-  void ThreadedInstancesLoader::PreloaderWorkerThread(ThreadedInstancesLoader* that)
-  {
-    Logging::ScopedThreadNameSetter setter(::GetLoaderThreadName(that->nameForLogs4Char_));
-
-    LOG(INFO) << "Loader thread has started";
-
-    while (true)
-    {
-      that->availableInstancesSemaphore_.Acquire(1); // reserve the slot early (since the instances are ordered, it is important that a single worker does not push dozens of small instances while we are waiting for a slot for a big instance)
-
-      std::unique_ptr<InstanceToPreload> instanceToPreload(dynamic_cast<InstanceToPreload*>(that->instancesToPreload_.Dequeue(0)));
-      if (instanceToPreload.get() == NULL || that->loadersShouldStop_)  // that's the signal to exit the thread
-      {
-        LOG(INFO) << "Loader thread has completed";
-        return;
-      }
-
-      const std::string& instanceId = instanceToPreload->GetId();
-      LOG(INFO) << "Loader thread is loading instance " << instanceId;
-
-      try
-      {
-        boost::shared_ptr<std::string> dicomContent(new std::string());
-        that->context_.ReadAttachment(*dicomContent, instanceToPreload->GetFileInfo(), true);
-
-        if (that->transcode_)
-        {
-          boost::shared_ptr<std::string> transcodedDicom(new std::string());
-          if (that->TranscodeDicom(*transcodedDicom, *dicomContent, instanceId))
-          {
-            dicomContent = transcodedDicom;
-          }
-        }
-
-        {
-          boost::mutex::scoped_lock lock(that->availableInstancesMutex_);
-          that->availableInstances_[instanceId] = dicomContent;
-          that->condInstanceAvailable_.notify_one();
-        }
-      }
-      catch (OrthancException& e)
-      {
-        LOG(ERROR) << "Failed to load instance " << instanceId << " error: " << e.GetDetails();
-        boost::mutex::scoped_lock lock(that->availableInstancesMutex_);
-        // store a NULL result to notify that we could not read the instance
-        that->availableInstances_[instanceId] = boost::shared_ptr<std::string>();
-        that->condInstanceAvailable_.notify_one();
-      }
-      catch (...)
-      {
-        LOG(ERROR) << "Failed to load instance " << instanceId << " unknown error";
-        boost::mutex::scoped_lock lock(that->availableInstancesMutex_);
-        // store a NULL result to notify that we could not read the instance
-        that->availableInstances_[instanceId] = boost::shared_ptr<std::string>();
-        that->condInstanceAvailable_.notify_one();
-      }
-    }
-  }
-
-
-  void ThreadedInstancesLoader::PreloadDicomInstance(const std::string& instanceId,
-                                                     const FileInfo& fileInfo)
-  {
-    instancesToPreload_.Enqueue(new InstanceToPreload(instanceId, fileInfo));
-  }
-
-
-  void ThreadedInstancesLoader::WaitDicomInstance(std::string& dicom,
-                                                  const std::string& instanceId)
-  {
-    boost::mutex::scoped_lock lock(availableInstancesMutex_);
-
-    // wait for this instance to be available but this might not be the one we are waiting for !
-    while (availableInstances_.find(instanceId) == availableInstances_.end())
-    {
-      condInstanceAvailable_.wait(lock);
-    }
-
-    boost::shared_ptr<std::string> dicomContent;
-
-    // this is the instance we were waiting for
-    dicomContent = availableInstances_[instanceId];
-    availableInstances_.erase(instanceId);
-    availableInstancesSemaphore_.Release(1);
-
-    if (dicomContent.get() == NULL)  // there has been an error while reading the file
-    {
-      throw OrthancException(ErrorCode_InexistentItem);
-    }
-
-    dicom.swap(*dicomContent);
-  }
-
-
-  bool ThreadedInstancesLoader::TranscodeDicom(std::string& transcodedBuffer,
-                                               const std::string& sourceBuffer,
-                                               const std::string& instanceId)
-  {
-    if (transcode_)
-    {
-      std::set<DicomTransferSyntax> syntaxes;
-      syntaxes.insert(transferSyntax_);
-
-      IDicomTranscoder::DicomImage source, transcoded;
-      source.SetExternalBuffer(sourceBuffer);
-
-      if (context_.GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew, lossyQuality_))
-      {
-        transcodedBuffer.assign(reinterpret_cast<const char*>(transcoded.GetBufferData()), transcoded.GetBufferSize());
-        return true;
-      }
-      else
-      {
-        LOG(INFO) << "Cannot transcode instance " << instanceId
-                  << " to transfer syntax: " << GetTransferSyntaxUid(transferSyntax_);
-      }
-    }
-
-    return false;
-  }
-}
--- a/OrthancServer/Sources/ServerJobs/ThreadedInstancesLoader.h	Mon Jun 01 22:56:23 2026 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/**
- * Orthanc - A Lightweight, RESTful DICOM Store
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2023 Osimis S.A., Belgium
- * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
- * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#pragma once
-
-#include "../../../OrthancFramework/Sources/Compatibility.h"
-#include "../../../OrthancFramework/Sources/Enumerations.h"
-#include "../../../OrthancFramework/Sources/FileStorage/FileInfo.h"
-#include "../../../OrthancFramework/Sources/MultiThreading/BlockingSharedMessageQueue.h"
-#include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h"
-
-#include <string>
-#include <boost/noncopyable.hpp>
-
-
-namespace Orthanc
-{
-  class ServerContext;
-
-  class ThreadedInstancesLoader ORTHANC_FINAL : public boost::noncopyable
-  {
-  private:
-    // Parameters from the constructor
-    ServerContext&                      context_;
-    bool                                transcode_;
-    DicomTransferSyntax                 transferSyntax_;
-    unsigned int                        lossyQuality_;
-    std::string                         nameForLogs4Char_;
-
-    // Internal variables
-    boost::condition_variable           condInstanceAvailable_;
-    std::map<std::string, boost::shared_ptr<std::string> >  availableInstances_;
-    boost::mutex                        availableInstancesMutex_;
-    Semaphore                           availableInstancesSemaphore_;
-    BlockingSharedMessageQueue          instancesToPreload_;
-    std::vector<boost::thread*>         threads_;
-    bool                                loadersShouldStop_;
-
-    static void PreloaderWorkerThread(ThreadedInstancesLoader* that);
-
-    bool TranscodeDicom(std::string& transcodedBuffer,
-                        const std::string& sourceBuffer,
-                        const std::string& instanceId);
-
-  public:
-    ThreadedInstancesLoader(ServerContext& context,
-                            size_t threadCount,
-                            bool transcode,
-                            DicomTransferSyntax transferSyntax,
-                            unsigned int lossyQuality,
-                            const std::string& nameForLogs4Char);
-
-    ~ThreadedInstancesLoader();
-
-    void Clear(bool isAbort);
-
-    void PreloadDicomInstance(const std::string& instanceId,
-                              const FileInfo& fileInfo);
-
-    void WaitDicomInstance(std::string& dicom,
-                           const std::string& instanceId);
-  };
-}
--- a/OrthancServer/Sources/ServerToolbox.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerToolbox.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -26,7 +26,6 @@
 
 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
-#include "../../OrthancFramework/Sources/FileStorage/StorageCache.h"
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/OrthancException.h"
 #include "Database/IDatabaseWrapper.h"
@@ -294,26 +293,31 @@
 
       if (limitToThisLevelDicomTags && instances.size() > 0) // in this case, we only need to rebuild one instance !
       {
-        ServerContext::DicomCacheLocker locker(context, instances.front());
-        context.GetIndex().ReconstructInstance(locker.GetDicom(), true, limitToLevel);
+        std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(instances.front()));
+        DicomDataSource::Dicom::Lock lock(*dicom);
+
+        context.GetIndex().ReconstructInstance(lock.GetContent(), true, limitToLevel);
       }
       else
       {
         for (std::list<std::string>::const_iterator 
               it = instances.begin(); it != instances.end(); ++it)
         {
-          ServerContext::DicomCacheLocker locker(context, *it);
+          std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(*it));
+          DicomDataSource::Dicom::Lock lock(*dicom);
 
           // Delay the reconstruction of DICOM-as-JSON to its next access through "ServerContext"
           context.GetIndex().DeleteAttachment(*it, FileContentType_DicomAsJson, false /* no revision */,
                                               -1 /* dummy revision */, "" /* dummy MD5 */);
           
-          context.GetIndex().ReconstructInstance(locker.GetDicom(), false, ResourceType_Instance /* dummy */);
+          context.GetIndex().ReconstructInstance(lock.GetContent(), false, ResourceType_Instance /* dummy */);
 
           if (reconstructFiles)
           {
+            std::unique_ptr<ParsedDicomFile> clone(lock.GetContent().Clone(true));
+
             std::string resultPublicId;  // ignored
-            std::unique_ptr<DicomInstanceToStore> dicomInstancetoStore(DicomInstanceToStore::CreateFromParsedDicomFile(locker.GetDicom()));
+            std::unique_ptr<DicomInstanceToStore> dicomInstancetoStore(DicomInstanceToStore::CreateFromParsedDicomFile(*clone));
 
             // TODO: TranscodeAndStore and specifically ServerIndex::Store have been "poluted" by the isReconstruct parameter
             // we should very likely refactor it
--- a/OrthancServer/Sources/ServerTranscoder.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerTranscoder.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -24,21 +24,91 @@
 #include "PrecompiledHeadersServer.h"
 #include "ServerTranscoder.h"
 
+#include "../../OrthancFramework/Sources/Cache/LeastRecentlyUsedIndex.h"
+#include "../../OrthancFramework/Sources/DataSource/DicomDataSource.h"
+#include "../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h"
+#include "../../OrthancFramework/Sources/DataSource/TranscoderDataSource.h"
 #include "../../OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.h"
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/OrthancException.h"
 #include "../Plugins/Engine/OrthancPlugins.h"
+#include "DicomInstanceToStore.h"
 #include "OrthancConfiguration.h"
 
+#include <boost/thread.hpp>
 #include <dcmtk/dcmdata/dcfilefo.h>
 
 
+static const size_t MAX_CACHE_SIZE = 10000;
+
 namespace Orthanc
 {
+  namespace
+  {
+    enum WorkingSource
+    {
+      WorkingSource_Unknown,
+      WorkingSource_Builtin,
+      WorkingSource_PluginsDecoder,
+      WorkingSource_PluginsTranscoder
+    };
+  }
+
+  class ServerTranscoder::PImpl
+  {
+  private:
+    boost::mutex  mutex_;
+    LeastRecentlyUsedIndex<std::string, WorkingSource>  workingSources_;
+
+  public:
+    PImpl()
+    {
+    }
+
+    WorkingSource LookupWorkingSource(const std::string& attachmentId)
+    {
+      boost::mutex::scoped_lock lock(mutex_);
+
+      WorkingSource source;
+      if (workingSources_.Contains(attachmentId, source))
+      {
+        return source;
+      }
+      else
+      {
+        return WorkingSource_Unknown;
+      }
+    }
+
+    void SetWorkingSource(const std::string& attachmentId,
+                          WorkingSource source)
+    {
+      if (source == WorkingSource_Unknown)
+      {
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+      }
+      else
+      {
+        boost::mutex::scoped_lock lock(mutex_);
+
+        assert(MAX_CACHE_SIZE > 0);
+
+        if (workingSources_.GetSize() >= MAX_CACHE_SIZE &&
+            !workingSources_.Contains(attachmentId))
+        {
+          workingSources_.RemoveOldest();
+        }
+
+        workingSources_.AddOrMakeMostRecent(attachmentId, source);
+      }
+    }
+  };
+
   ServerTranscoder::ServerTranscoder(unsigned int maxConcurrentDcmtkTranscoder) :
 #if ORTHANC_ENABLE_PLUGINS == 1
     plugins_(NULL),
 #endif
+    pimpl_(new PImpl),
     dcmtkTranscoder_(new DcmtkTranscoder(maxConcurrentDcmtkTranscoder)),
     builtinDecoderTranscoderOrder_(BuiltinDecoderTranscoderOrder_After)
   {
@@ -67,92 +137,282 @@
 #endif
 
 
-  ImageAccessor* ServerTranscoder::DecodeFrame(const ParsedDicomFile& parsedDicom,
-                                               const void* buffer,
-                                               size_t size,
+  bool ServerTranscoder::HasPluginsDecoder() const
+  {
+#if ORTHANC_ENABLE_PLUGINS == 1
+    return (plugins_ != NULL &&
+            plugins_->HasCustomImageDecoder());
+#else
+    return false;
+#endif
+  }
+
+
+  bool ServerTranscoder::HasPluginsTranscoder() const
+  {
+#if ORTHANC_ENABLE_PLUGINS == 1
+    return (plugins_ != NULL &&
+            plugins_->HasCustomTranscoder());
+#else
+    return false;
+#endif
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameBuiltin(const ParsedDicomFile& dicom,
+                                                      unsigned int frameIndex)
+  {
+    // Use Orthanc's built-in decoder
+
+    try
+    {
+      return dicom.DecodeFrame(frameIndex);
+    }
+    catch (const OrthancException&) // NOLINT(bugprone-empty-catch)
+    {
+    }
+
+    return NULL;
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsDecoder(const void* buffer,
+                                                                  size_t size,
+                                                                  unsigned int frameIndex)
+  {
+#if ORTHANC_ENABLE_PLUGINS == 1
+    if (HasPluginsDecoder())
+    {
+      try
+      {
+        return plugins_->Decode(buffer, size, frameIndex);
+      }
+      catch (const OrthancException&) // NOLINT(bugprone-empty-catch)
+      {
+      }
+    }
+#endif
+
+    return NULL;
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsTranscoder(const void* buffer,
+                                                                     size_t size,
+                                                                     unsigned int frameIndex)
+  {
+    /**
+     * Contrarily to "ServerTranscoder::Transcode()", this method
+     * doesn't use "dcmtkTranscoder_", as "DecodeFrameBuiltin()" would
+     * have succeeded in this case.
+     **/
+
+#if ORTHANC_ENABLE_PLUGINS == 1
+    if (HasPluginsTranscoder())
+    {
+      DicomImage transcoded;
+      DicomImage source;
+      std::set<DicomTransferSyntax> allowedSyntaxes;
+
+      source.SetExternalBuffer(buffer, size);
+      allowedSyntaxes.insert(DicomTransferSyntax_LittleEndianExplicit);
+
+      if (plugins_->Transcode(transcoded, source, allowedSyntaxes, TranscodingSopInstanceUidMode_AllowNew))
+      {
+        try
+        {
+          std::unique_ptr<ParsedDicomFile> dicom(transcoded.ReleaseAsParsedDicomFile());
+          return DecodeFrameBuiltin(*dicom, frameIndex);
+        }
+        catch (const OrthancException&) // NOLINT(bugprone-empty-catch)
+        {
+        }
+      }
+    }
+#endif
+
+    return NULL;
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameBuiltin(const boost::shared_ptr<DataSourceReader>& dicomReader,
+                                                      const FileInfo& attachment,
+                                                      unsigned int frameIndex)
+  {
+    std::unique_ptr<DicomDataSource::Dicom> dicom(
+      DicomDataSource::Execute(*dicomReader, DicomDataSource::CreateWholeRequest(attachment)));
+
+    DicomDataSource::Dicom::Lock lock(*dicom);
+
+    return DecodeFrameBuiltin(lock.GetContent(), frameIndex);
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsDecoder(const boost::shared_ptr<DataSourceReader>& storageAreaReader,
+                                                                  const FileInfo& attachment,
+                                                                  unsigned int frameIndex)
+  {
+    if (!HasPluginsDecoder())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      std::unique_ptr<StorageAreaDataSource::Range> range(
+        StorageAreaDataSource::Execute(
+          *storageAreaReader, StorageAreaDataSource::CreateAttachmentRequest(attachment, true /* uncompress */)));
+
+      return DecodeFrameUsingPluginsDecoder(range->GetData(), range->GetSize(), frameIndex);
+    }
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsTranscoder(const boost::shared_ptr<DataSourceReader>& transcoderReader,
+                                                                     const FileInfo& attachment,
+                                                                     unsigned int frameIndex)
+  {
+    if (!HasPluginsDecoder())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      std::unique_ptr<TranscoderDataSource::Transcoded> transcoded(
+        TranscoderDataSource::Execute(*transcoderReader, TranscoderDataSource::CreateRequest(
+                                        attachment, DicomTransferSyntax_LittleEndianExplicit,
+                                        TranscodingSopInstanceUidMode_AllowNew, false /* no lossy quality specified */, 0)));
+
+      TranscoderDataSource::Transcoded::LockAsParsed lock(*transcoded);
+
+      return DecodeFrameBuiltin(lock.GetContent(), frameIndex);
+    }
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrame(const DicomInstanceToStore& image,
                                                unsigned int frameIndex)
   {
     std::unique_ptr<ImageAccessor> decoded;
 
     if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
     {
-      // Use Orthanc's built-in decoder
-
-      try
+      decoded.reset(DecodeFrameBuiltin(image.GetParsedDicomFile(), frameIndex));
+      if (decoded.get() != NULL)
       {
-        decoded.reset(parsedDicom.DecodeFrame(frameIndex));
-        if (decoded.get() != NULL)
-        {
-          return decoded.release();
-        }
-      }
-      catch (const OrthancException&) // NOLINT(bugprone-empty-catch)
-      { // ignore, we'll try other alternatives
+        return decoded.release();
       }
     }
 
-#if ORTHANC_ENABLE_PLUGINS == 1
-    if (plugins_ != NULL &&
-        plugins_->HasCustomImageDecoder())
+    decoded.reset(DecodeFrameUsingPluginsDecoder(image.GetBufferData(), image.GetBufferSize(), frameIndex));
+    if (decoded.get() != NULL)
     {
-      try
-      {
-        decoded.reset(plugins_->Decode(buffer, size, frameIndex));
-      }
-      catch (const OrthancException&) // NOLINT(bugprone-empty-catch)
-      {
-      }
+      return decoded.release();
+    }
 
+    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
+    {
+      decoded.reset(DecodeFrameBuiltin(image.GetParsedDicomFile(), frameIndex));
       if (decoded.get() != NULL)
       {
         return decoded.release();
       }
-      else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
+    }
+
+    decoded.reset(DecodeFrameUsingPluginsTranscoder(image.GetBufferData(), image.GetBufferSize(), frameIndex));
+    if (decoded.get() != NULL)
+    {
+      return decoded.release();
+    }
+
+    return NULL;
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrame(const boost::shared_ptr<DataSourceReader>& dicomReader,        // For built-in decoding
+                                               const boost::shared_ptr<DataSourceReader>& storageAreaReader,  // For plugin-based decoding
+                                               const boost::shared_ptr<DataSourceReader>& transcoderReader,   // For transcoding-based decoding
+                                               const FileInfo& attachment,
+                                               unsigned int frameIndex)
+  {
+    // Step 1: Try with the last decoder that successfully handled this DICOM attachment
+
+    const WorkingSource source = pimpl_->LookupWorkingSource(attachment.GetUuid());
+
+    std::unique_ptr<ImageAccessor> decoded;
+
+    switch (source)
+    {
+      case WorkingSource_Unknown:
+        break;
+
+      case WorkingSource_Builtin:
+        decoded.reset(DecodeFrameBuiltin(dicomReader, attachment, frameIndex));
+        break;
+
+      case WorkingSource_PluginsDecoder:
+        decoded.reset(DecodeFrameUsingPluginsDecoder(storageAreaReader, attachment, frameIndex));
+        break;
+
+      case WorkingSource_PluginsTranscoder:
+        decoded.reset(DecodeFrameUsingPluginsTranscoder(transcoderReader, attachment, frameIndex));
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+
+    if (decoded.get() != NULL)
+    {
+      return decoded.release();
+    }
+
+    // Step 2: If this attachment is unknown, try the available decoders
+
+    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
+    {
+      decoded.reset(DecodeFrameBuiltin(dicomReader, attachment, frameIndex));
+
+      if (decoded.get() != NULL)
       {
-        LOG(INFO) << "The installed image decoding plugins cannot handle an image, "
-                  << "fallback to the built-in DCMTK decoder";
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_Builtin);
+        return decoded.release();
       }
     }
-#endif
+
+    if (HasPluginsDecoder())
+    {
+      decoded.reset(DecodeFrameUsingPluginsDecoder(storageAreaReader, attachment, frameIndex));
+
+      if (decoded.get() != NULL)
+      {
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_PluginsDecoder);
+        return decoded.release();
+      }
+    }
 
     if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
     {
-      try
+      decoded.reset(DecodeFrameBuiltin(dicomReader, attachment, frameIndex));
+
+      if (decoded.get() != NULL)
       {
-        decoded.reset(parsedDicom.DecodeFrame(frameIndex));
-        if (decoded.get() != NULL)
-        {
-          return decoded.release();
-        }
-      }
-      catch (OrthancException& e)
-      {
-        LOG(INFO) << "Failed to decode a DICOM frame: " << e.GetDetails();
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_Builtin);
+        return decoded.release();
       }
     }
 
-#if ORTHANC_ENABLE_PLUGINS == 1
-    if (plugins_ != NULL &&
-        plugins_->HasCustomTranscoder())
+    if (HasPluginsTranscoder())
     {
-      LOG(INFO) << "The plugins and built-in image decoders failed to decode a frame, "
-                << "trying to transcode the file to LittleEndianExplicit using the plugins.";
-      DicomImage explicitTemporaryImage;
-      DicomImage source;
-      std::set<DicomTransferSyntax> allowedSyntaxes;
+      decoded.reset(DecodeFrameUsingPluginsTranscoder(transcoderReader, attachment, frameIndex));
 
-      source.SetExternalBuffer(buffer, size);
-      allowedSyntaxes.insert(DicomTransferSyntax_LittleEndianExplicit);
-
-      if (Transcode(explicitTemporaryImage, source, allowedSyntaxes, TranscodingSopInstanceUidMode_AllowNew))
+      if (decoded.get() != NULL)
       {
-        std::unique_ptr<ParsedDicomFile> file(explicitTemporaryImage.ReleaseAsParsedDicomFile());
-        return file->DecodeFrame(frameIndex);
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_PluginsTranscoder);
+        return decoded.release();
       }
     }
-#endif
 
-    return NULL;  // TODO-Streaming - Throw exception here?
+    return NULL;
   }
 
 
--- a/OrthancServer/Sources/ServerTranscoder.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/ServerTranscoder.h	Tue Jun 02 07:41:56 2026 +0200
@@ -24,12 +24,18 @@
 #pragma once
 
 #include "../../OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h"
+#include "../../OrthancFramework/Sources/FileStorage/FileInfo.h"
 #include "../../OrthancFramework/Sources/Images/ImageAccessor.h"
 #include "ServerEnumerations.h"
 
+#include <boost/shared_ptr.hpp>
+
 
 namespace Orthanc
 {
+  class DataSourceReader;
+  class DicomInstanceToStore;
+
 #if ORTHANC_ENABLE_PLUGINS == 1
   class OrthancPlugins;
 #endif
@@ -37,23 +43,58 @@
   class ServerTranscoder : public IDicomTranscoder
   {
   private:
+    class PImpl;
+
 #if ORTHANC_ENABLE_PLUGINS == 1
     OrthancPlugins* plugins_;
 #endif
 
+    boost::shared_ptr<PImpl>           pimpl_;
     std::unique_ptr<IDicomTranscoder>  dcmtkTranscoder_;
     BuiltinDecoderTranscoderOrder      builtinDecoderTranscoderOrder_;
 
+    ImageAccessor* DecodeFrameBuiltin(const ParsedDicomFile& dicom,
+                                      unsigned int frameIndex);
+
+    ImageAccessor* DecodeFrameUsingPluginsDecoder(const void* buffer,
+                                                  size_t size,
+                                                  unsigned int frameIndex);
+
+    ImageAccessor* DecodeFrameUsingPluginsTranscoder(const void* buffer,
+                                                     size_t size,
+                                                     unsigned int frameIndex);
+
+    ImageAccessor* DecodeFrameBuiltin(const boost::shared_ptr<DataSourceReader>& dicomReader,
+                                      const FileInfo& attachment,
+                                      unsigned int frameIndex);
+
+    ImageAccessor* DecodeFrameUsingPluginsDecoder(const boost::shared_ptr<DataSourceReader>& storageAreaReader,
+                                                  const FileInfo& attachment,
+                                                  unsigned int frameIndex);
+
+    ImageAccessor* DecodeFrameUsingPluginsTranscoder(const boost::shared_ptr<DataSourceReader>& transcoderReader,
+                                                     const FileInfo& attachment,
+                                                     unsigned int frameIndex);
+
   public:
-    ServerTranscoder(unsigned int maxConcurrentDcmtkTranscoder);
+    explicit ServerTranscoder(unsigned int maxConcurrentDcmtkTranscoder);
 
 #if ORTHANC_ENABLE_PLUGINS == 1
     void SetPlugins(OrthancPlugins& plugins);
 #endif
 
-    ImageAccessor* DecodeFrame(const ParsedDicomFile& parsedDicom,
-                               const void* buffer,  // buffer that is the source of the ParsedDicomFile
-                               size_t size,
+    bool HasPluginsDecoder() const;
+
+    bool HasPluginsTranscoder() const;
+
+    // This version should only be used by plugins
+    ImageAccessor* DecodeFrame(const DicomInstanceToStore& image,
+                               unsigned int frameIndex);
+
+    ImageAccessor* DecodeFrame(const boost::shared_ptr<DataSourceReader>& dicomReader,        // For built-in decoding
+                               const boost::shared_ptr<DataSourceReader>& storageAreaReader,  // For plugin-based decoding
+                               const boost::shared_ptr<DataSourceReader>& transcoderReader,   // For transcoding-based decoding
+                               const FileInfo& attachment,
                                unsigned int frameIndex);
 
     // This method can be used even if the global option
--- a/OrthancServer/Sources/main.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -53,9 +53,11 @@
 #include "ServerJobs/DicomRetrieveScuBaseJob.h"
 #include "ServerJobs/StorageCommitmentScpJob.h"
 #include "ServerToolbox.h"
+#include "ServerTranscoder.h"
 #include "StorageCommitmentReports.h"
 
 #include <boost/algorithm/string/predicate.hpp>
+#include <dcmtk/dcmnet/dimse.h>  // For STATUS_STORE_Error_CannotUnderstand
 
 #if defined(_WIN32) || defined(__CYGWIN__)
 #include <windows.h>
@@ -1608,19 +1610,14 @@
         lock.GetConfiguration().SetServerIndex(context.GetIndex());
       }
 
-      std::unique_ptr<ServerTranscoder> transcoder(new ServerTranscoder(maxDcmtkConcurrentTranscoders));
-
 #if ORTHANC_ENABLE_PLUGINS == 1
       if (plugins_ != NULL)
       {
         plugins_->SetServerContext(context_);
         context_.SetPlugins(*plugins_);
         context_.GetIndex().SetMaxDatabaseRetries(plugins_->GetMaxDatabaseRetries());
-        transcoder->SetPlugins(*plugins_);
       }
 #endif
-
-      context.SetTranscoder(transcoder.release());
     }
 
     ~ServerContextConfigurator()
@@ -1637,8 +1634,6 @@
         context_.ResetPlugins();
       }
 #endif
-
-      context_.ResetTranscoder();
     }
   };
 }
@@ -1709,8 +1704,14 @@
     DicomAssociationParameters::SetDefaultRemoteCertificateRequired(
       lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true));
   }
+
+  std::unique_ptr<ServerTranscoder> transcoder(new ServerTranscoder(maxDcmtkConcurrentTranscoders));
+
+#if ORTHANC_ENABLE_PLUGINS == 1
+  transcoder->SetPlugins(*plugins);
+#endif
   
-  ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs, readOnly);
+  ServerContext context(database, storageArea, transcoder.release(), false /* not running unit tests */, maxCompletedJobs, readOnly);
 
   {
     OrthancConfiguration::ReaderLock lock;
@@ -2180,7 +2181,8 @@
           SQLiteDatabaseWrapper inMemoryDatabase;
           inMemoryDatabase.Open();
           PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea);
-          ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
+          ServerContext context(inMemoryDatabase, inMemoryStorage, NULL /* no transcoder */,
+                                true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
           OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
           restApi.GenerateOpenApiDocumentation(openapi);
           context.Stop();
@@ -2231,7 +2233,8 @@
           SQLiteDatabaseWrapper inMemoryDatabase;
           inMemoryDatabase.Open();
           PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea);
-          ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
+          ServerContext context(inMemoryDatabase, inMemoryStorage, NULL /* no transcoder */,
+                                true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
           OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
           restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html");
           context.Stop();
--- a/OrthancServer/UnitTestsSources/ServerConfigTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/ServerConfigTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -39,7 +39,7 @@
   PluginStorageAreaAdapter storage(new MemoryStorageArea);
   SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
   db.Open();
-  ServerContext context(db, storage, true /* running unit tests */, 10, false);
+  ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false);
 
   { // default config -> all SOP Classes should be accepted
     std::set<std::string> s;
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -730,7 +730,7 @@
   PluginStorageAreaAdapter storage(new FilesystemStorage(path));
   SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
   db.Open();
-  ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+  ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
   context.SetupJobsEngine(true, false);
 
   ServerIndex& index = context.GetIndex();
@@ -812,7 +812,7 @@
   PluginStorageAreaAdapter storage(new FilesystemStorage(path));
   SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
   db.Open();
-  ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+  ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
   context.SetupJobsEngine(true, false);
   ServerIndex& index = context.GetIndex();
 
@@ -935,7 +935,7 @@
     PluginStorageAreaAdapter storage(new MemoryStorageArea);
     SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
     db.Open();
-    ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+    ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
     context.SetupJobsEngine(true, false);
     context.SetCompressionEnabled(true);
 
@@ -1002,9 +1002,11 @@
     ASSERT_EQ("name", tmp["0010,0010"]["Value"].asString());
     
     {
-      ServerContext::DicomCacheLocker locker(context, id);
+      std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id));
+      DicomDataSource::Dicom::Lock lock(*dicom);
+
       std::string tmp;
-      locker.GetDicom().GetTagValue(tmp, DICOM_TAG_PATIENT_NAME);
+      lock.GetContent().GetTagValue(tmp, DICOM_TAG_PATIENT_NAME);
       ASSERT_EQ("name", tmp);
     }
 
@@ -1057,9 +1059,11 @@
       ASSERT_EQ("overwritten", tmp["0010,0010"]["Value"].asString());
     
       {
-        ServerContext::DicomCacheLocker locker(context, id);
+        std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id));
+        DicomDataSource::Dicom::Lock lock(*dicom);
+
         std::string tmp;
-        locker.GetDicom().GetTagValue(tmp, DICOM_TAG_PATIENT_NAME);
+        lock.GetContent().GetTagValue(tmp, DICOM_TAG_PATIENT_NAME);
         ASSERT_EQ("overwritten", tmp);
       }
     }
@@ -1074,9 +1078,11 @@
       ASSERT_EQ("name", tmp["0010,0010"]["Value"].asString());
     
       {
-        ServerContext::DicomCacheLocker locker(context, id);
+        std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id));
+        DicomDataSource::Dicom::Lock lock(*dicom);
+
         std::string tmp;
-        locker.GetDicom().GetTagValue(tmp, DICOM_TAG_PATIENT_NAME);
+        lock.GetContent().GetTagValue(tmp, DICOM_TAG_PATIENT_NAME);
         ASSERT_EQ("name", tmp);
       }
     }
@@ -1100,7 +1106,7 @@
     PluginStorageAreaAdapter storage(new MemoryStorageArea);
     SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
     db.Open();
-    ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+    ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
     context.SetupJobsEngine(true, false);
     context.SetCompressionEnabled(compression);
 
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -566,7 +566,7 @@
       storage_(new MemoryStorageArea)
     {
       db_.Open();
-      context_.reset(new ServerContext(db_, storage_, true /* running unit tests */, 10, false /* readonly */));
+      context_.reset(new ServerContext(db_, storage_, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */));
       context_->SetupJobsEngine(true, false);
     }
 
@@ -1021,9 +1021,11 @@
   std::string study, series;
 
   {
-    ServerContext::DicomCacheLocker lock(GetContext(), instance);
-    study = lock.GetDicom().GetHasher().HashStudy();
-    series = lock.GetDicom().GetHasher().HashSeries();
+    std::unique_ptr<DicomDataSource::Dicom> dicom(GetContext().ReadParsedDicom(instance));
+    DicomDataSource::Dicom::Lock lock(*dicom);
+
+    study = lock.GetContent().GetHasher().HashStudy();
+    series = lock.GetContent().GetHasher().HashSeries();
   }
 
   {
--- a/OrthancServer/UnitTestsSources/SizeOfTests.cpp	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/SizeOfTests.cpp	Tue Jun 02 07:41:56 2026 +0200
@@ -24,6 +24,11 @@
 #include "PrecompiledHeadersUnitTests.h"
 #include <gtest/gtest.h>
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
+
 #include "../../OrthancFramework/Sources/Cache/ICachePageProvider.h"
 #include "../../OrthancFramework/Sources/Cache/ICacheable.h"
 #include "../../OrthancFramework/Sources/Cache/LeastRecentlyUsedIndex.h"
@@ -101,7 +106,6 @@
 #include "../../OrthancFramework/Sources/FileStorage/IStorageArea.h"
 #include "../../OrthancFramework/Sources/FileStorage/MemoryStorageArea.h"
 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
-#include "../../OrthancFramework/Sources/FileStorage/StorageCache.h"
 #include "../../OrthancFramework/Sources/HttpClient.h"
 #include "../../OrthancFramework/Sources/HttpServer/BufferHttpSender.h"
 #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpHandler.h"
--- a/OrthancServer/UnitTestsSources/SizeOfTests.impl.h	Mon Jun 01 22:56:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/SizeOfTests.impl.h	Tue Jun 02 07:41:56 2026 +0200
@@ -105,7 +105,6 @@
   printf("sizeof(::Orthanc::SharedLibrary) == %d\n", static_cast<int>(sizeof(::Orthanc::SharedLibrary)));
   printf("sizeof(::Orthanc::SharedMessageQueue) == %d\n", static_cast<int>(sizeof(::Orthanc::SharedMessageQueue)));
   printf("sizeof(::Orthanc::StorageAccessor) == %d\n", static_cast<int>(sizeof(::Orthanc::StorageAccessor)));
-  printf("sizeof(::Orthanc::StorageCache) == %d\n", static_cast<int>(sizeof(::Orthanc::StorageCache)));
   printf("sizeof(::Orthanc::StreamBlockReader) == %d\n", static_cast<int>(sizeof(::Orthanc::StreamBlockReader)));
   printf("sizeof(::Orthanc::StringMatcher) == %d\n", static_cast<int>(sizeof(::Orthanc::StringMatcher)));
   printf("sizeof(::Orthanc::StringOperationValue) == %d\n", static_cast<int>(sizeof(::Orthanc::StringOperationValue)));