1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NET_HTTP_CACHE_PROXY_H
17 #define NET_HTTP_CACHE_PROXY_H
18 
19 #include "net_http_cache_strategy.h"
20 #include "net_http_request.h"
21 #include "net_http_response.h"
22 #include "lru_cache_disk_handler.h"
23 #include "net_http_request_context.h"
24 #include "constant.h"
25 
26 namespace OHOS::NetStack::Http {
27 class CacheProxy final {
28 public:
29     CacheProxy() = delete;
30 
31     explicit CacheProxy(HttpRequest &requestOptions);
32 
33     bool ReadResponseFromCache(RequestContext *context);
34 
35     void WriteResponseToCache(const HttpResponse &response);
36 
37     static void RunCacheWithSize(size_t capacity);
38 
39     static void RunCache();
40 
41     static void FlushCache();
42 
43     static void StopCacheAndDelete();
44 
45 private:
46     std::string key_;
47     HttpCacheStrategy strategy_;
48 };
49 } // namespace OHOS::NetStack::Http
50 #endif // NET_HTTP_CACHE_PROXY_H
51