annotate OrthancFramework/Sources/FileStorage/StorageCache.cpp @ 4900:ea5f1c6ed07e

fix cache of storage area
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 20 Feb 2022 16:29:33 +0100
parents 43e613a7756b
children f656fb878b50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 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 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
36 static std::string GetCacheKey(const std::string& uuid,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
37 FileContentType contentType)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
39 return uuid + ":" + boost::lexical_cast<std::string>(contentType);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
41
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
42
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 void StorageCache::SetMaximumSize(size_t size)
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
44 {
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 cache_.SetMaximumSize(size);
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
47
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
48
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 void StorageCache::Add(const std::string& uuid,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 FileContentType contentType,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 const std::string& value)
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
52 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
53 const std::string key = GetCacheKey(uuid, contentType);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
54 cache_.Add(key, value);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
56
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
57
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 void StorageCache::Add(const std::string& uuid,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 FileContentType contentType,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 const void* buffer,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 size_t size)
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 const std::string key = GetCacheKey(uuid, contentType);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
64 cache_.Add(key, buffer, size);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
65 }
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
66
4826
6c276fac0cc0 fix storage cache for user attachment -> the cache is ignoring them
Alain Mazy <am@osimis.io>
parents: 4792
diff changeset
67
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
68 void StorageCache::Invalidate(const std::string& uuid,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
69 FileContentType contentType)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
71 const std::string key = GetCacheKey(uuid, contentType);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
72 cache_.Invalidate(key);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
74
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
75
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
76 bool StorageCache::Fetch(std::string& value,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 const std::string& uuid,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 FileContentType contentType)
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
80 const std::string key = GetCacheKey(uuid, contentType);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
81 if (cache_.Fetch(value, key))
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
82 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
83 LOG(INFO) << "Read attachment \"" << uuid << "\" with content type "
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
84 << boost::lexical_cast<std::string>(contentType) << " from cache";
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
85 return true;
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
86 }
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
87 else
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 return false;
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
92 }