bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
EffectiveUrlCache.h
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the BES http package, part of the Hyrax data server.
4
5// Copyright (c) 2020 OPeNDAP, Inc.
6// Author: Nathan Potter <ndp@opendap.org>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23
24// Authors:
25// ndp Nathan Potter <ndp@opendap.org>
26
27#ifndef _bes_http_EffectiveUrlCache_h_
28#define _bes_http_EffectiveUrlCache_h_ 1
29
30#include <memory>
31#include <map>
32#include <unordered_map>
33#include <string>
34#include <mutex>
35
36#include "BESObj.h"
37#include "BESRegex.h" // for std::unique_ptr<BESRegex>
38
39namespace http {
40
41class EffectiveUrl;
42class url;
43
53class EffectiveUrlCache : public BESObj {
54private:
55 EffectiveUrlCache() = default;
56
57 std::mutex d_cache_lock_mutex;
58
59 std::map<std::string, std::shared_ptr<http::EffectiveUrl>> d_effective_urls;
60
61 // URLs that match are not cached.
62 std::unique_ptr<BESRegex> d_skip_regex = nullptr;
63
64 int d_enabled = -1;
65
66 std::shared_ptr<EffectiveUrl> get_cached_eurl(std::string const &url_key);
67
68 void set_skip_regex();
69
70 bool is_enabled();
71
72 friend class EffectiveUrlCacheTest;
73
74public:
85 static EffectiveUrlCache *TheCache() {
86 // Create a local static object the first time the function is called
87 static EffectiveUrlCache instance;
88 return &instance;
89 }
90
91 EffectiveUrlCache(const EffectiveUrlCache &src) = delete;
92 EffectiveUrlCache &operator=(const EffectiveUrlCache &rhs) = delete;
93
94 ~EffectiveUrlCache() override = default;
95
96 std::shared_ptr<EffectiveUrl> get_effective_url(std::shared_ptr<url> source_url);
97
98 void dump(std::ostream &strm) const override;
99
100private:
101 std::string dump() const {
102 std::stringstream sstrm;
103 dump(sstrm);
104 return sstrm.str();
105 }
106};
107
108} // namespace http
109
110#endif // _bes_http_EffectiveUrlCache_h_
111
top level BES object to house generic methods
Definition BESObj.h:54
std::shared_ptr< EffectiveUrl > get_effective_url(std::shared_ptr< url > source_url)
static EffectiveUrlCache * TheCache()
Get the singleton EffectiveUrlCache instance.
Parse a URL into the protocol, host, path and query parts.
Definition url_impl.h:44
utility class for the HTTP catalog module
Definition TheBESKeys.h:51