comparison OrthancFramework/Sources/FileStorage/StorageCache.h @ 5807:8279eaab0d1d attach-custom-data

merged default -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 11:39:52 +0200
parents f7adfb22e20e
children
comparison
equal deleted inserted replaced
5085:79f98ee4f04b 5807:8279eaab0d1d
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium 6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 * 8 *
8 * This program is free software: you can redistribute it and/or 9 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License 10 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of 11 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
35 /** 36 /**
36 * Note: this class is thread safe 37 * Note: this class is thread safe
37 **/ 38 **/
38 class ORTHANC_PUBLIC StorageCache : public boost::noncopyable 39 class ORTHANC_PUBLIC StorageCache : public boost::noncopyable
39 { 40 {
41 public:
42
43 // The StorageCache is only accessible through this accessor.
44 // It will make sure that only one user will fill load data and fill
45 // the cache if multiple users try to access the same item at the same time.
46 // This scenario happens a lot when multiple workers from a viewer access
47 // the same file.
48 class Accessor : public MemoryStringCache::Accessor
49 {
50 StorageCache& storageCache_;
51 public:
52 explicit Accessor(StorageCache& cache);
53
54 void Add(const std::string& uuid,
55 FileContentType contentType,
56 const std::string& value);
57
58 void AddStartRange(const std::string& uuid,
59 FileContentType contentType,
60 const std::string& value);
61
62 void Add(const std::string& uuid,
63 FileContentType contentType,
64 const void* buffer,
65 size_t size);
66
67 bool Fetch(std::string& value,
68 const std::string& uuid,
69 FileContentType contentType);
70
71 bool FetchStartRange(std::string& value,
72 const std::string& uuid,
73 FileContentType contentType,
74 uint64_t end /* exclusive */);
75
76 bool FetchTranscodedInstance(std::string& value,
77 const std::string& uuid,
78 DicomTransferSyntax targetSyntax);
79
80 void AddTranscodedInstance(const std::string& uuid,
81 DicomTransferSyntax targetSyntax,
82 const void* buffer,
83 size_t size);
84 };
85
40 private: 86 private:
41 MemoryStringCache cache_; 87 MemoryStringCache cache_;
42 88 std::set<DicomTransferSyntax> subKeysTransferSyntax_;
89 boost::mutex subKeysMutex_;
90
43 public: 91 public:
44 void SetMaximumSize(size_t size); 92 void SetMaximumSize(size_t size);
45 93
94 void Invalidate(const std::string& uuid,
95 FileContentType contentType);
96
97 size_t GetCurrentSize() const;
98
99 size_t GetNumberOfItems() const;
100
101 private:
46 void Add(const std::string& uuid, 102 void Add(const std::string& uuid,
47 FileContentType contentType, 103 FileContentType contentType,
48 const std::string& value); 104 const std::string& value);
49 105
50 void AddStartRange(const std::string& uuid, 106 void AddStartRange(const std::string& uuid,
54 void Add(const std::string& uuid, 110 void Add(const std::string& uuid,
55 FileContentType contentType, 111 FileContentType contentType,
56 const void* buffer, 112 const void* buffer,
57 size_t size); 113 size_t size);
58 114
59 void Invalidate(const std::string& uuid,
60 FileContentType contentType);
61
62 bool Fetch(std::string& value, 115 bool Fetch(std::string& value,
63 const std::string& uuid, 116 const std::string& uuid,
64 FileContentType contentType); 117 FileContentType contentType);
65 118
66 bool FetchStartRange(std::string& value, 119 bool FetchStartRange(std::string& value,