Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/BaseWebService.cpp @ 872:733c6db3e5a3 am-dev
limiting the size of the cache
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 01 Jul 2019 13:36:51 +0200 |
parents | c0fcb2757b0a |
children | 200b4e0dddfc |
rev | line source |
---|---|
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
1 /** |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
6 * |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
11 * |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
16 * |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
19 **/ |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
20 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
21 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
22 #include "BaseWebService.h" |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
23 |
736
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
24 #include "../../Messages/IObservable.h" |
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
25 #include "../../../Platforms/Generic/IOracleCommand.h" |
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
26 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
27 #include <Core/OrthancException.h> |
736
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
28 |
435
e641d3978856
WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents:
434
diff
changeset
|
29 #include <boost/shared_ptr.hpp> |
872 | 30 #include <algorithm> |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
31 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
32 namespace Deprecated |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
33 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
34 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
35 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
36 class BaseWebService::BaseWebServicePayload : public Orthanc::IDynamicObject |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
37 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
38 private: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
39 std::auto_ptr< OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage> > userSuccessHandler_; |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
40 std::auto_ptr< OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage> > userFailureHandler_; |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
41 std::auto_ptr< Orthanc::IDynamicObject> userPayload_; |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
42 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
43 public: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
44 BaseWebServicePayload(OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* userSuccessHandler, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
45 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* userFailureHandler, |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
46 Orthanc::IDynamicObject* userPayload) : |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
47 userSuccessHandler_(userSuccessHandler), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
48 userFailureHandler_(userFailureHandler), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
49 userPayload_(userPayload) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
50 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
51 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
52 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
53 void HandleSuccess(const IWebService::HttpRequestSuccessMessage& message) const |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
54 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
55 if (userSuccessHandler_.get() != NULL) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
56 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
57 // recreate a success message with the user payload |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
58 IWebService::HttpRequestSuccessMessage successMessage(message.GetUri(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
59 message.GetAnswer(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
60 message.GetAnswerSize(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
61 message.GetAnswerHttpHeaders(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
62 userPayload_.get()); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
63 userSuccessHandler_->Apply(successMessage); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
64 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
65 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
66 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
67 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
68 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
69 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
70 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
71 void HandleFailure(const IWebService::HttpRequestErrorMessage& message) const |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
72 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
73 if (userFailureHandler_.get() != NULL) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
74 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
75 // recreate a failure message with the user payload |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
76 IWebService::HttpRequestErrorMessage failureMessage(message.GetUri(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
77 userPayload_.get()); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
78 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
79 userFailureHandler_->Apply(failureMessage); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
80 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
81 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
82 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
83 }; |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
84 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
85 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
86 void BaseWebService::GetAsync(const std::string& uri, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
87 const HttpHeaders& headers, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
88 Orthanc::IDynamicObject* payload /* takes ownership */, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
89 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
90 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
91 unsigned int timeoutInSeconds) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
92 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
93 if (cache_.find(uri) == cache_.end()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
94 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
95 GetAsyncInternal(uri, headers, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
96 new BaseWebService::BaseWebServicePayload(successCallback, failureCallback, payload), // ownership is transfered |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
97 new OrthancStone::Callable<BaseWebService, IWebService::HttpRequestSuccessMessage> |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
98 (*this, &BaseWebService::CacheAndNotifyHttpSuccess), |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
99 new OrthancStone::Callable<BaseWebService, IWebService::HttpRequestErrorMessage> |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
100 (*this, &BaseWebService::NotifyHttpError), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
101 timeoutInSeconds); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
102 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
103 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
104 { |
872 | 105 // put the uri on top of the most recently accessed list |
106 std::deque<std::string>::iterator it = std::find(orderedCacheKeys_.begin(), orderedCacheKeys_.end(), uri); | |
107 if (it != orderedCacheKeys_.end()) | |
108 { | |
109 std::string uri = *it; | |
110 orderedCacheKeys_.erase(it); | |
111 orderedCacheKeys_.push_front(uri); | |
112 } | |
113 | |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
114 // create a command and "post" it to the Oracle so it is executed and commited "later" |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
115 NotifyHttpSuccessLater(cache_[uri], payload, successCallback); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
116 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
117 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
118 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
119 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
120 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
121 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
122 void BaseWebService::NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
123 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
124 if (message.HasPayload()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
125 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
126 dynamic_cast<const BaseWebServicePayload&>(message.GetPayload()).HandleSuccess(message); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
127 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
128 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
129 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
131 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
132 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
133 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
134 void BaseWebService::CacheAndNotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
135 { |
872 | 136 while (cacheCurrentSize_ + message.GetAnswerSize() > cacheMaxSize_ && orderedCacheKeys_.size() > 0) |
137 { | |
138 const std::string& oldestUri = orderedCacheKeys_.back(); | |
139 HttpCache::iterator it = cache_.find(oldestUri); | |
140 if (it != cache_.end()) | |
141 { | |
142 cacheCurrentSize_ -= it->second->GetAnswerSize(); | |
143 cache_.erase(it); | |
144 } | |
145 orderedCacheKeys_.pop_back(); | |
146 | |
147 } | |
148 | |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
149 cache_[message.GetUri()] = boost::shared_ptr<CachedHttpRequestSuccessMessage>(new CachedHttpRequestSuccessMessage(message)); |
872 | 150 orderedCacheKeys_.push_front(message.GetUri()); |
151 cacheCurrentSize_ += message.GetAnswerSize(); | |
152 | |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
153 NotifyHttpSuccess(message); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
154 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
155 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
156 void BaseWebService::NotifyHttpError(const IWebService::HttpRequestErrorMessage& message) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
157 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
158 if (message.HasPayload()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
159 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
160 dynamic_cast<const BaseWebServicePayload&>(message.GetPayload()).HandleFailure(message); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
161 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
162 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
163 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
165 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
166 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
167 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
168 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
169 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
170 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
171 } |