Mercurial > hg > orthanc
annotate OrthancFramework/Sources/FileStorage/StorageCache.cpp @ 4826:6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 25 Nov 2021 15:36:11 +0100 |
parents | 434843934307 |
children | 7053502fbf97 |
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 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
6 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 * 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
|
8 * 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
|
9 * 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
|
10 * the License, or (at your option) any later version. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * 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
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 * 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
|
15 * Lesser General Public License for more details. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 * |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * 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
|
18 * License along with this program. If not, see |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 **/ |
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 #include "../PrecompiledHeaders.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 #include "StorageCache.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 #include "../Compatibility.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 #include "../OrthancException.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 namespace Orthanc |
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 bool IsAcceptedContentType(FileContentType contentType) |
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 return contentType == FileContentType_Dicom || |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 contentType == FileContentType_DicomUntilPixelData || |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 contentType == FileContentType_DicomAsJson; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 const char* ToString(FileContentType contentType) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 switch (contentType) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 case FileContentType_Dicom: |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 return "dicom"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 case FileContentType_DicomUntilPixelData: |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 return "dicom-header"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
48 case FileContentType_DicomAsJson: |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
49 return "dicom-json"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 default: |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
51 throw OrthancException(ErrorCode_InternalError, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 "ContentType not supported in StorageCache"); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
53 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
56 bool GetCacheKey(std::string& key, const std::string& uuid, FileContentType contentType) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 { |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
58 if (contentType == FileContentType_Unknown || contentType >= FileContentType_StartUser) |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
59 { |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
60 return false; |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
61 } |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
62 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 key = uuid + ":" + std::string(ToString(contentType)); |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
64 |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
65 return true; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 void StorageCache::SetMaximumSize(size_t size) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 cache_.SetMaximumSize(size); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 void StorageCache::Add(const std::string& uuid, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 FileContentType contentType, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 const std::string& value) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 if (!IsAcceptedContentType(contentType)) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
79 return; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 std::string key; |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
83 |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
84 if (GetCacheKey(key, uuid, contentType)) |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
85 { |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
86 cache_.Add(key, value); |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
87 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 void StorageCache::Add(const std::string& uuid, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 FileContentType contentType, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 const void* buffer, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 size_t size) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 if (!IsAcceptedContentType(contentType)) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
97 return; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 std::string key; |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
101 |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
102 if (GetCacheKey(key, uuid, contentType)) |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
103 { |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
104 cache_.Add(key, buffer, size); |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
105 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
106 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
107 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 void StorageCache::Invalidate(const std::string& uuid, FileContentType contentType) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
110 std::string key; |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
111 |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
112 if (GetCacheKey(key, uuid, contentType)) |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
113 { |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
114 cache_.Invalidate(key); |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
115 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
117 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 bool StorageCache::Fetch(std::string& value, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
119 const std::string& uuid, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
120 FileContentType contentType) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
121 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
122 if (!IsAcceptedContentType(contentType)) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
123 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
124 return false; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
125 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
126 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 std::string key; |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
128 if (GetCacheKey(key, uuid, contentType)) |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
129 { |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
130 return cache_.Fetch(value, key); |
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
131 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 |
4826
6c276fac0cc0
fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents:
4792
diff
changeset
|
133 return false; |
4792
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 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
137 } |