Mercurial > hg > orthanc
annotate OrthancFramework/Sources/FileStorage/StorageCache.cpp @ 5841:57ab63fe9108 find-refactoring tip
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 24 Oct 2024 15:08:43 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 /** |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
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:
5431
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * the License, or (at your option) any later version. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * Lesser General Public License for more details. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 * License along with this program. If not, see |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 **/ |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 #include "../PrecompiledHeaders.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 #include "StorageCache.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 #include "../Compatibility.h" |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
29 #include "../Logging.h" |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 #include "../OrthancException.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
32 #include <boost/lexical_cast.hpp> |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 namespace Orthanc |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 { |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
37 static std::string GetCacheKeyFullFile(const std::string& uuid, |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
38 FileContentType contentType) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 { |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
40 return uuid + ":" + boost::lexical_cast<std::string>(contentType) + ":1"; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 } |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
42 |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
43 |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
44 static std::string GetCacheKeyStartRange(const std::string& uuid, |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
45 FileContentType contentType) |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
46 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
47 return uuid + ":" + boost::lexical_cast<std::string>(contentType) + ":0"; |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
48 } |
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:
5185
diff
changeset
|
49 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
50 |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
51 static std::string GetCacheKeyTranscodedInstance(const std::string& uuid, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
52 DicomTransferSyntax transferSyntax) |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
53 { |
5427 | 54 return uuid + ":ts:" + GetTransferSyntaxUid(transferSyntax); |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
55 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
56 |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
57 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 void StorageCache::SetMaximumSize(size_t size) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 cache_.SetMaximumSize(size); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 } |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
62 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
64 void StorageCache::Invalidate(const std::string& uuid, |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
65 FileContentType contentType) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 { |
5427 | 67 std::set<DicomTransferSyntax> transferSyntaxes; |
68 | |
69 { | |
70 boost::mutex::scoped_lock lock(subKeysMutex_); | |
71 transferSyntaxes = subKeysTransferSyntax_; | |
72 } | |
73 | |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
74 // invalidate full file, start range file and possible transcoded instances |
5427 | 75 const std::string keyFullFile = GetCacheKeyFullFile(uuid, contentType); |
76 cache_.Invalidate(keyFullFile); | |
77 | |
78 const std::string keyPartialFile = GetCacheKeyStartRange(uuid, contentType); | |
79 cache_.Invalidate(keyPartialFile); | |
80 | |
81 for (std::set<DicomTransferSyntax>::const_iterator it = transferSyntaxes.begin(); it != transferSyntaxes.end(); ++it) | |
82 { | |
83 const std::string keyTransferSyntax = GetCacheKeyTranscodedInstance(uuid, *it); | |
84 cache_.Invalidate(keyTransferSyntax); | |
85 } | |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 } |
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:
5185
diff
changeset
|
87 |
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:
5185
diff
changeset
|
88 |
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:
5185
diff
changeset
|
89 StorageCache::Accessor::Accessor(StorageCache& cache) |
5427 | 90 : MemoryStringCache::Accessor(cache.cache_), |
91 storageCache_(cache) | |
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:
5185
diff
changeset
|
92 { |
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:
5185
diff
changeset
|
93 } |
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:
5185
diff
changeset
|
94 |
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:
5185
diff
changeset
|
95 void StorageCache::Accessor::Add(const std::string& uuid, |
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:
5185
diff
changeset
|
96 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:
5185
diff
changeset
|
97 const std::string& value) |
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:
5185
diff
changeset
|
98 { |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 |
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:
5185
diff
changeset
|
100 std::string key = GetCacheKeyFullFile(uuid, 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:
5185
diff
changeset
|
101 MemoryStringCache::Accessor::Add(key, value); |
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:
5185
diff
changeset
|
102 } |
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:
5185
diff
changeset
|
103 |
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:
5185
diff
changeset
|
104 void StorageCache::Accessor::AddStartRange(const std::string& uuid, |
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:
5185
diff
changeset
|
105 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:
5185
diff
changeset
|
106 const std::string& value) |
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:
5185
diff
changeset
|
107 { |
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:
5185
diff
changeset
|
108 const std::string key = GetCacheKeyStartRange(uuid, 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:
5185
diff
changeset
|
109 MemoryStringCache::Accessor::Add(key, value); |
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:
5185
diff
changeset
|
110 } |
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:
5185
diff
changeset
|
111 |
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:
5185
diff
changeset
|
112 void StorageCache::Accessor::Add(const std::string& uuid, |
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:
5185
diff
changeset
|
113 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:
5185
diff
changeset
|
114 const void* 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:
5185
diff
changeset
|
115 size_t size) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 { |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
117 const std::string key = GetCacheKeyFullFile(uuid, contentType); |
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:
5185
diff
changeset
|
118 MemoryStringCache::Accessor::Add(key, reinterpret_cast<const char*>(buffer), size); |
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:
5185
diff
changeset
|
119 } |
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:
5185
diff
changeset
|
120 |
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:
5185
diff
changeset
|
121 bool StorageCache::Accessor::Fetch(std::string& value, |
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:
5185
diff
changeset
|
122 const std::string& uuid, |
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:
5185
diff
changeset
|
123 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:
5185
diff
changeset
|
124 { |
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:
5185
diff
changeset
|
125 const std::string key = GetCacheKeyFullFile(uuid, 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:
5185
diff
changeset
|
126 if (MemoryStringCache::Accessor::Fetch(value, key)) |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
127 { |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
128 LOG(INFO) << "Read attachment \"" << uuid << "\" with content type " |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
129 << boost::lexical_cast<std::string>(contentType) << " from cache"; |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
130 return true; |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
131 } |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
132 else |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 return false; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
135 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 } |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
137 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
138 bool StorageCache::Accessor::FetchTranscodedInstance(std::string& value, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
139 const std::string& uuid, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
140 DicomTransferSyntax targetSyntax) |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
141 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
142 const std::string key = GetCacheKeyTranscodedInstance(uuid, targetSyntax); |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
143 if (MemoryStringCache::Accessor::Fetch(value, key)) |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
144 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
145 LOG(INFO) << "Read instance \"" << uuid << "\" transcoded to " |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
146 << GetTransferSyntaxUid(targetSyntax) << " from cache"; |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
147 return true; |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
148 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
149 else |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
150 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
151 return false; |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
152 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
153 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
154 |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
155 void StorageCache::Accessor::AddTranscodedInstance(const std::string& uuid, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
156 DicomTransferSyntax targetSyntax, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
157 const void* buffer, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
158 size_t size) |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
159 { |
5427 | 160 { |
161 boost::mutex::scoped_lock lock(storageCache_.subKeysMutex_); | |
162 storageCache_.subKeysTransferSyntax_.insert(targetSyntax); | |
163 } | |
164 | |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
165 const std::string key = GetCacheKeyTranscodedInstance(uuid, targetSyntax); |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
166 MemoryStringCache::Accessor::Add(key, reinterpret_cast<const char*>(buffer), size); |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
167 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
168 |
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:
5185
diff
changeset
|
169 bool StorageCache::Accessor::FetchStartRange(std::string& value, |
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:
5185
diff
changeset
|
170 const std::string& uuid, |
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:
5185
diff
changeset
|
171 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:
5185
diff
changeset
|
172 uint64_t end /* exclusive */) |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
173 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
174 const std::string keyPartialFile = GetCacheKeyStartRange(uuid, contentType); |
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:
5185
diff
changeset
|
175 if (MemoryStringCache::Accessor::Fetch(value, keyPartialFile) && value.size() >= end) |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
176 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
177 if (value.size() > end) // the start range that has been cached is larger than the requested value |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
178 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
179 value.resize(end); |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
180 } |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
181 |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
182 LOG(INFO) << "Read start of attachment \"" << uuid << "\" with content type " |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
183 << boost::lexical_cast<std::string>(contentType) << " from cache"; |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
184 return true; |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
185 } |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
186 |
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:
5185
diff
changeset
|
187 return false; |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
188 } |
5431 | 189 |
190 | |
191 size_t StorageCache::GetCurrentSize() const | |
192 { | |
193 return cache_.GetCurrentSize(); | |
194 } | |
195 | |
196 size_t StorageCache::GetNumberOfItems() const | |
197 { | |
198 return cache_.GetNumberOfItems(); | |
199 } | |
200 | |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
201 } |