annotate OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 5791:7fadeb395359 default

fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
author Alain Mazy <am@orthanc.team>
date Wed, 18 Sep 2024 10:38:02 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5420
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
25 #include "../PrecompiledHeaders.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "StorageAccessor.h"
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
27 #include "StorageCache.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
29 #include "../Logging.h"
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
30 #include "../StringMemoryBuffer.h"
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
31 #include "../Compatibility.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
32 #include "../Compression/ZlibCompressor.h"
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
33 #include "../MetricsRegistry.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
34 #include "../OrthancException.h"
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
35 #include "../Toolbox.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
36
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
37 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
38 # include "../HttpServer/HttpStreamTranscoder.h"
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
39 #endif
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
40
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
41
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
42 static const std::string METRICS_CREATE_DURATION = "orthanc_storage_create_duration_ms";
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
43 static const std::string METRICS_READ_DURATION = "orthanc_storage_read_duration_ms";
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
44 static const std::string METRICS_REMOVE_DURATION = "orthanc_storage_remove_duration_ms";
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
45 static const std::string METRICS_READ_BYTES = "orthanc_storage_read_bytes";
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
46 static const std::string METRICS_WRITTEN_BYTES = "orthanc_storage_written_bytes";
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
47 static const std::string METRICS_CACHE_HIT_COUNT = "orthanc_storage_cache_hit_count";
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
48 static const std::string METRICS_CACHE_MISS_COUNT = "orthanc_storage_cache_miss_count";
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
49
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
50
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 namespace Orthanc
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
53 class StorageAccessor::MetricsTimer : public boost::noncopyable
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
54 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
55 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
56 std::unique_ptr<MetricsRegistry::Timer> timer_;
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
57
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
58 public:
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
59 MetricsTimer(StorageAccessor& that,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
60 const std::string& name)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
61 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
62 if (that.metrics_ != NULL)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
63 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
64 timer_.reset(new MetricsRegistry::Timer(*that.metrics_, name));
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
65 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
66 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
67 };
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
68
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
69
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
70 StorageAccessor::StorageAccessor(IStorageArea& area) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
71 area_(area),
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
72 cache_(NULL),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
73 metrics_(NULL)
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
74 {
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
75 }
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
76
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
77
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
78 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
79 StorageCache& cache) :
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
80 area_(area),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
81 cache_(&cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
82 metrics_(NULL)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
83 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
84 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
85
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
86
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
87 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
88 MetricsRegistry& metrics) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
89 area_(area),
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
90 cache_(NULL),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
91 metrics_(&metrics)
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
92 {
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
93 }
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
94
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
95 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
96 StorageCache& cache,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
97 MetricsRegistry& metrics) :
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
98 area_(area),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
99 cache_(&cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
100 metrics_(&metrics)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
101 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
102 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
103
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
104
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
105 FileInfo StorageAccessor::Write(const void* data,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
106 size_t size,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
107 FileContentType type,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
108 CompressionType compression,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
109 bool storeMd5)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
111 std::string uuid = Toolbox::GenerateUuid();
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
112
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
113 std::string md5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
114
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
115 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
116 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
117 Toolbox::ComputeMD5(md5, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
118 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
119
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
120 switch (compression)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
122 case CompressionType_None:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
123 {
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
124 {
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
125 MetricsTimer timer(*this, METRICS_CREATE_DURATION);
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
126 area_.Create(uuid, data, size, type);
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
127 }
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
128
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
129 if (metrics_ != NULL)
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
130 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5329
diff changeset
131 metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, size);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
132 }
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
133
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
134 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
135 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
136 StorageCache::Accessor cacheAccessor(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
137 cacheAccessor.Add(uuid, type, data, size);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
138 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
139
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
140 return FileInfo(uuid, type, size, md5);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
141 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
142
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
143 case CompressionType_ZlibWithSize:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
144 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
145 ZlibCompressor zlib;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
146
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
147 std::string compressed;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
148 zlib.Compress(compressed, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
149
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
150 std::string compressedMD5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
151
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
152 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
153 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
154 Toolbox::ComputeMD5(compressedMD5, compressed);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
155 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
156
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
157 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
158 MetricsTimer timer(*this, METRICS_CREATE_DURATION);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
159
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
160 if (compressed.size() > 0)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
161 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
162 area_.Create(uuid, &compressed[0], compressed.size(), type);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
163 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
164 else
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
165 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
166 area_.Create(uuid, NULL, 0, type);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
167 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
168 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
169
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
170 if (metrics_ != NULL)
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
171 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5329
diff changeset
172 metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, compressed.size());
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
173 }
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
174
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
175 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
176 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
177 StorageCache::Accessor cacheAccessor(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
178 cacheAccessor.Add(uuid, type, data, size); // always add uncompressed data to cache
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
179 }
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
180
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
181 return FileInfo(uuid, type, size, md5,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
182 CompressionType_ZlibWithSize, compressed.size(), compressedMD5);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
183 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
184
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
185 default:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
186 throw OrthancException(ErrorCode_NotImplemented);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
190 FileInfo StorageAccessor::Write(const std::string &data,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
191 FileContentType type,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
192 CompressionType compression,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
193 bool storeMd5)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
194 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
195 return Write((data.size() == 0 ? NULL : data.c_str()),
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
196 data.size(), type, compression, storeMd5);
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
197 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
198
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
199
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
200 void StorageAccessor::Read(std::string& content,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
201 const FileInfo& info)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
203 if (cache_ == NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
204 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
205 ReadWholeInternal(content, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
206 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
207 else
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
209 StorageCache::Accessor cacheAccessor(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
210
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
211 if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
212 {
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
213 if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
214 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
215 metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
216 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
217
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
218 ReadWholeInternal(content, info);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
219
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
220 // always store the uncompressed data in cache
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
221 cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
222 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
223 else if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
224 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
225 metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
226 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
227 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
228 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
229
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
230 void StorageAccessor::ReadWholeInternal(std::string& content,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
231 const FileInfo& info)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
232 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
233 switch (info.GetCompressionType())
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
234 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
235 case CompressionType_None:
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
236 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
237 std::unique_ptr<IMemoryBuffer> buffer;
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
238
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
239 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
240 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
241 buffer.reset(area_.Read(info.GetUuid(), info.GetContentType()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
242 }
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
243
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
244 if (metrics_ != NULL)
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
245 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
246 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize());
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
247 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
248
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
249 buffer->MoveToString(content);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
250
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
251 break;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
252 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
253
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
254 case CompressionType_ZlibWithSize:
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
255 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
256 ZlibCompressor zlib;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
257
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
258 std::unique_ptr<IMemoryBuffer> compressed;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
259
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
260 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
261 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
262 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType()));
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
263 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
264
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
265 if (metrics_ != NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
266 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
267 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, compressed->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
268 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
269
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
270 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
271
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
272 break;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
273 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
274
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
275 default:
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
276 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
277 throw OrthancException(ErrorCode_NotImplemented);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
278 }
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
280
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
281 // TODO Check the validity of the uncompressed MD5?
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
282 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
283
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
284
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
285 void StorageAccessor::ReadRaw(std::string& content,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
286 const FileInfo& info)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
287 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
288 if (cache_ == NULL || info.GetCompressionType() != CompressionType_None)
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
289 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
290 ReadRawInternal(content, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
291 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
292 else
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
293 {// use the cache only if the data is uncompressed.
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
294 StorageCache::Accessor cacheAccessor(*cache_);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
295
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
296 if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
297 {
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
298 if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
299 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
300 metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
301 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
302
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
303 ReadRawInternal(content, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
304
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
305 cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
306 }
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
307 else if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
308 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
309 metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
310 }
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
311 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
312 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
313
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
314 void StorageAccessor::ReadRawInternal(std::string& content,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
315 const FileInfo& info)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
316 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
317 std::unique_ptr<IMemoryBuffer> buffer;
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
318
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
319 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
320 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
321 buffer.reset(area_.Read(info.GetUuid(), info.GetContentType()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
322 }
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
323
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
324 if (metrics_ != NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
325 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
326 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
327 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
328
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
329 buffer->MoveToString(content);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
330 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
331
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
332
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
333 void StorageAccessor::Remove(const std::string& fileUuid,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
334 FileContentType type)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
335 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
336 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
337 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
338 cache_->Invalidate(fileUuid, type);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
339 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
340
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
341 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
342 MetricsTimer timer(*this, METRICS_REMOVE_DURATION);
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
343 area_.Remove(fileUuid, type);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
344 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
345 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
346
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
347
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
348 void StorageAccessor::Remove(const FileInfo &info)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
349 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
350 Remove(info.GetUuid(), info.GetContentType());
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
351 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
352
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
353
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
354 void ReadStartRangeFromAreaInternal(std::string& target,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
355 IStorageArea& area,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
356 const std::string& fileUuid,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
357 FileContentType contentType,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
358 uint64_t end /* exclusive */)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
359 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
360
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
361 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
362
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
363 void StorageAccessor::ReadStartRange(std::string& target,
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
364 const FileInfo& info,
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
365 uint64_t end /* exclusive */)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
366 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
367 if (cache_ == NULL)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
368 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
369 ReadStartRangeInternal(target, info, end);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
370 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
371 else
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
372 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
373 StorageCache::Accessor accessorStartRange(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
374 if (!accessorStartRange.FetchStartRange(target, info.GetUuid(), info.GetContentType(), end))
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
375 {
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
376 // the start range is not in cache, let's check if the whole file is
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
377 StorageCache::Accessor accessorWhole(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
378 if (!accessorWhole.Fetch(target, info.GetUuid(), info.GetContentType()))
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
379 {
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
380 if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
381 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
382 metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
383 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
384
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
385 // if nothing is in the cache, let's read and cache only the start
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
386 ReadStartRangeInternal(target, info, end);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
387 accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
388 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
389 else
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
390 {
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
391 if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
392 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
393 metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
394 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
395
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
396 // we have read the whole file, check size and resize if needed
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
397 if (target.size() < end)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
398 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
399 throw OrthancException(ErrorCode_CorruptedFile);
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
400 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
401
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
402 target.resize(end);
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
403 }
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
404 }
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
405 else if (metrics_ != NULL)
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
406 {
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
407 metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
408 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
409 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
410 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
411
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
412 void StorageAccessor::ReadStartRangeInternal(std::string& target,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
413 const FileInfo& info,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
414 uint64_t end /* exclusive */)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
415 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
416 std::unique_ptr<IMemoryBuffer> buffer;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
417
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
418 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
419 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
420 buffer.reset(area_.ReadRange(info.GetUuid(), info.GetContentType(), 0, end));
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
421 assert(buffer->GetSize() == end);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
422 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
423
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
424 if (metrics_ != NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
425 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
426 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
427 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
428
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
429 buffer->MoveToString(target);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
430 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
431
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
432
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
433 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
434 void StorageAccessor::SetupSender(BufferHttpSender& sender,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
435 const FileInfo& info,
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
436 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
437 {
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
438 Read(sender.GetBuffer(), info);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
439
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
440 sender.SetContentType(mime);
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
441
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
442 const char* extension;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
443 switch (info.GetContentType())
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
444 {
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
445 case FileContentType_Dicom:
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
446 case FileContentType_DicomUntilPixelData:
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
447 extension = ".dcm";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
448 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
449
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
450 case FileContentType_DicomAsJson:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
451 extension = ".json";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
452 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
453
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
454 default:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
455 // Non-standard content type
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
456 extension = "";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
457 }
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
458
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
459 sender.SetContentFilename(info.GetUuid() + std::string(extension));
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
460 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
461 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
462
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
463
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
464 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
465 void StorageAccessor::AnswerFile(HttpOutput& output,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
466 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
467 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
468 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
469 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
470 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
471 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
472
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
473
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
474 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
475 void StorageAccessor::AnswerFile(HttpOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
476 const FileInfo& info,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
477 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
478 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
479 BufferHttpSender sender;
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
480 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
481
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
482 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
483 output.Answer(transcoder);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
484 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
485 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
486
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
487
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
488 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
489 void StorageAccessor::AnswerFile(RestApiOutput& output,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
490 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
491 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
492 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
493 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
494 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
495 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
496
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
497
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
498 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
499 void StorageAccessor::AnswerFile(RestApiOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
500 const FileInfo& info,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
501 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
502 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
503 BufferHttpSender sender;
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
504 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
505
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
506 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
507 output.AnswerStream(transcoder);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
509 #endif
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }