# HG changeset patch # User Sebastien Jodogne # Date 1778686007 -7200 # Node ID 967edd507e0eedeedc53f667b26e5050f159e6fc # Parent 40683448f9ae03113814eada614264059780ecb7 getting rid of IObjectSizeProvider diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/Cache/IObjectSizeProvider.h --- a/OrthancFramework/Sources/Cache/IObjectSizeProvider.h Wed May 13 16:45:00 2026 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +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 - * . - **/ - - -#pragma once - -#include "../IDynamicObject.h" - - -namespace Orthanc -{ - class ORTHANC_PUBLIC IObjectSizeProvider : public boost::noncopyable - { - public: - virtual ~IObjectSizeProvider() - { - } - - virtual size_t GetSize(const IDynamicObject& object) const = 0; - }; -} diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/Cache/SharedObjectCache.cpp --- a/OrthancFramework/Sources/Cache/SharedObjectCache.cpp Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/Cache/SharedObjectCache.cpp Wed May 13 17:26:47 2026 +0200 @@ -81,16 +81,10 @@ } - SharedObjectCache::SharedObjectCache(IObjectSizeProvider* provider, - size_t capacity) : - provider_(provider), + SharedObjectCache::SharedObjectCache(size_t capacity) : capacity_(capacity), currentSize_(0) { - if (provider == NULL) - { - throw OrthancException(ErrorCode_NullPointer); - } } @@ -127,17 +121,16 @@ void SharedObjectCache::Store(const std::string& id, - const boost::shared_ptr& value) + const boost::shared_ptr& value, + size_t size) { if (value.get() == NULL) { throw OrthancException(ErrorCode_NullPointer); } - assert(provider_.get() != NULL); - size_t size = provider_->GetSize(*value) + sizeof(Item); - // Caching items with zero size would break the logic of "MakeRoom()", hence "sizeof(Item)" + size += sizeof(Item); assert(size != 0); if (size > capacity_) diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/Cache/SharedObjectCache.h --- a/OrthancFramework/Sources/Cache/SharedObjectCache.h Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/Cache/SharedObjectCache.h Wed May 13 17:26:47 2026 +0200 @@ -24,8 +24,8 @@ #pragma once +#include "../IDynamicObject.h" #include "../MultiThreading/Mutex.h" -#include "IObjectSizeProvider.h" #include "LeastRecentlyUsedIndex.h" #include @@ -40,18 +40,16 @@ typedef std::map Content; - Mutex mutex_; - std::unique_ptr provider_; - LeastRecentlyUsedIndex lru_; - Content content_; - size_t capacity_; - size_t currentSize_; + Mutex mutex_; + LeastRecentlyUsedIndex lru_; + Content content_; + size_t capacity_; + size_t currentSize_; void MakeRoom(size_t newObjectSize); public: - SharedObjectCache(IObjectSizeProvider* provider /* takes ownership */, - size_t capacity); + SharedObjectCache(size_t capacity); ~SharedObjectCache(); @@ -67,7 +65,8 @@ * be read by other threads. **/ void Store(const std::string& id, - const boost::shared_ptr& value); + const boost::shared_ptr& value, + size_t size); void Invalidate(const std::string& id); }; diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/DataSource/DataSourceReader.cpp --- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp Wed May 13 17:26:47 2026 +0200 @@ -100,7 +100,7 @@ if (!error && cache_ && hasCacheKey) { - cache_->Store(cacheKey, value); + cache_->Store(cacheKey, value, source_.GetValueSize(*value)); } } @@ -111,7 +111,7 @@ if (!error) { - size = source_.GetSize(*value); + size = source_.GetValueSize(*value); budget_->Acquire(size); // may block; "DataSourceAnswer" CAN be destroyed here } @@ -167,10 +167,9 @@ } - void DataSourceReader::CreateCache(IObjectSizeProvider* provider /* takes ownership */, - size_t capacity) + void DataSourceReader::CreateCache(size_t capacity) { - cache_ = boost::make_shared(provider, capacity); + cache_ = boost::make_shared(capacity); } diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/DataSource/DataSourceReader.h --- a/OrthancFramework/Sources/DataSource/DataSourceReader.h Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DataSourceReader.h Wed May 13 17:26:47 2026 +0200 @@ -60,8 +60,7 @@ return *source_; } - void CreateCache(IObjectSizeProvider* provider /* takes ownership */, - size_t capacity); + void CreateCache(size_t capacity); void SetMaximumMemory(uint64_t maximumMemory); diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/DataSource/IDataSource.h --- a/OrthancFramework/Sources/DataSource/IDataSource.h Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/IDataSource.h Wed May 13 17:26:47 2026 +0200 @@ -24,14 +24,20 @@ #pragma once -#include "../Cache/IObjectSizeProvider.h" +#include "../IDynamicObject.h" #include "IDataIdentifier.h" namespace Orthanc { - class ORTHANC_PUBLIC IDataSource : public IObjectSizeProvider + class ORTHANC_PUBLIC IDataSource : public boost::noncopyable { public: + virtual ~IDataSource() + { + } + virtual IDynamicObject* Load(const IDataIdentifier& identifier) = 0; + + virtual size_t GetValueSize(const IDynamicObject& value) const = 0; }; } diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp --- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Wed May 13 17:26:47 2026 +0200 @@ -114,10 +114,10 @@ return *area_; } - size_t StorageAreaDataSource::GetSize(const IDynamicObject& object) const + size_t StorageAreaDataSource::GetValueSize(const IDynamicObject& value) const { - const Value& value = dynamic_cast(object); - return value.GetBuffer().GetSize(); + const Value& tmp = dynamic_cast(value); + return tmp.GetBuffer().GetSize(); } IDynamicObject* StorageAreaDataSource::Load(const IDataIdentifier& identifier) diff -r 40683448f9ae -r 967edd507e0e OrthancFramework/Sources/DataSource/StorageAreaDataSource.h --- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Wed May 13 16:45:00 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Wed May 13 17:26:47 2026 +0200 @@ -49,7 +49,7 @@ IPluginStorageArea& GetArea() const; - virtual size_t GetSize(const IDynamicObject& object) const ORTHANC_OVERRIDE; + virtual size_t GetValueSize(const IDynamicObject& value) const ORTHANC_OVERRIDE; virtual IDynamicObject* Load(const IDataIdentifier& identifier) ORTHANC_OVERRIDE;