Mercurial > hg > orthanc
annotate OrthancFramework/Sources/FileStorage/StorageCache.cpp @ 5437:85da6dcd0e08
merge
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 22 Nov 2023 09:39:35 +0100 |
parents | 4be5f117aa0d |
children | 48b8dae6dc77 |
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 |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4906
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4906
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * the License, or (at your option) any later version. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * 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
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * 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
|
16 * Lesser General Public License for more details. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 * 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
|
19 * License along with this program. If not, see |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 **/ |
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 #include "../PrecompiledHeaders.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 #include "StorageCache.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 #include "../Compatibility.h" |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
28 #include "../Logging.h" |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 #include "../OrthancException.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
31 #include <boost/lexical_cast.hpp> |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 |
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 namespace Orthanc |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 { |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
36 static std::string GetCacheKeyFullFile(const std::string& uuid, |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
37 FileContentType contentType) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 { |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
39 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
|
40 } |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
41 |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
42 |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
43 static std::string GetCacheKeyStartRange(const std::string& uuid, |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
44 FileContentType contentType) |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
45 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
46 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
|
47 } |
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
|
48 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
49 |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
50 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
|
51 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
|
52 { |
5427 | 53 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
|
54 } |
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 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 void StorageCache::SetMaximumSize(size_t size) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 cache_.SetMaximumSize(size); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 } |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
61 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
63 void StorageCache::Invalidate(const std::string& uuid, |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
64 FileContentType contentType) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 { |
5427 | 66 std::set<DicomTransferSyntax> transferSyntaxes; |
67 | |
68 { | |
69 boost::mutex::scoped_lock lock(subKeysMutex_); | |
70 transferSyntaxes = subKeysTransferSyntax_; | |
71 } | |
72 | |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
73 // invalidate full file, start range file and possible transcoded instances |
5427 | 74 const std::string keyFullFile = GetCacheKeyFullFile(uuid, contentType); |
75 cache_.Invalidate(keyFullFile); | |
76 | |
77 const std::string keyPartialFile = GetCacheKeyStartRange(uuid, contentType); | |
78 cache_.Invalidate(keyPartialFile); | |
79 | |
80 for (std::set<DicomTransferSyntax>::const_iterator it = transferSyntaxes.begin(); it != transferSyntaxes.end(); ++it) | |
81 { | |
82 const std::string keyTransferSyntax = GetCacheKeyTranscodedInstance(uuid, *it); | |
83 cache_.Invalidate(keyTransferSyntax); | |
84 } | |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 } |
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
|
86 |
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 StorageCache::Accessor::Accessor(StorageCache& cache) |
5427 | 89 : MemoryStringCache::Accessor(cache.cache_), |
90 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
|
91 { |
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 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
|
95 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
|
96 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
|
97 { |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 |
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
|
99 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
|
100 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
|
101 } |
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 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
|
104 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
|
105 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
|
106 { |
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 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
|
108 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
|
109 } |
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 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
|
112 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
|
113 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
|
114 size_t size) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
115 { |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
116 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
|
117 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
|
118 } |
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 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
|
121 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
|
122 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
|
123 { |
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 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
|
125 if (MemoryStringCache::Accessor::Fetch(value, key)) |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
126 { |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
127 LOG(INFO) << "Read attachment \"" << uuid << "\" with content type " |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
128 << boost::lexical_cast<std::string>(contentType) << " from cache"; |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
129 return true; |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
130 } |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
131 else |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 return false; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
135 } |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
136 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
141 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
|
142 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
|
143 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
144 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
|
145 << 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
|
146 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
|
147 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
148 else |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
149 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
150 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
|
151 } |
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 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
|
155 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
|
156 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
|
157 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
|
158 { |
5427 | 159 { |
160 boost::mutex::scoped_lock lock(storageCache_.subKeysMutex_); | |
161 storageCache_.subKeysTransferSyntax_.insert(targetSyntax); | |
162 } | |
163 | |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
164 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
|
165 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
|
166 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5420
diff
changeset
|
167 |
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
|
168 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
|
169 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
|
170 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
|
171 uint64_t end /* exclusive */) |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
172 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
173 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
|
174 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
|
175 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
176 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
|
177 { |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
178 value.resize(end); |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
179 } |
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 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
|
182 << boost::lexical_cast<std::string>(contentType) << " from cache"; |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
183 return true; |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
184 } |
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
185 |
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
|
186 return false; |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4900
diff
changeset
|
187 } |
5431 | 188 |
189 | |
190 size_t StorageCache::GetCurrentSize() const | |
191 { | |
192 return cache_.GetCurrentSize(); | |
193 } | |
194 | |
195 size_t StorageCache::GetNumberOfItems() const | |
196 { | |
197 return cache_.GetNumberOfItems(); | |
198 } | |
199 | |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
200 } |