bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESDapFunctionResponseCache.h
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of Hyrax, A C++ implementation of the OPeNDAP Data
4// Access Protocol.
5
6// Copyright (c) 2016 OPeNDAP, Inc.
7// Author: Nathan David Potter <ndp@opendap.org>
8// James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26#ifndef _bes_dap_function_response_cache_h
27#define _bes_dap_function_response_cache_h
28
29#include <string>
30
31#include "BESFileLockingCache.h"
32
34
35namespace libdap {
36class DDS;
37class ConstraintEvaluator;
38class BaseTypeFactory;
39}
40
71
72class BESDapFunctionResponseCache: public BESFileLockingCache {
73private:
74 static bool d_enabled;
75 static BESDapFunctionResponseCache *d_instance;
76
80 static void delete_instance() {
81 delete d_instance;
82 d_instance = 0;
83 }
84
89 BESDapFunctionResponseCache();
90 BESDapFunctionResponseCache(const BESDapFunctionResponseCache &src);
92
93 bool is_valid(const std::string &cache_file_name, const std::string &dataset);
94
95 std::string get_resource_id(libdap::DDS *dds, const std::string &constraint);
96 std::string get_hash_basename(const std::string &resource_id);
97
98 libdap::DDS *read_cached_data(std::istream &cached_data);
99
100 libdap::DDS *write_dataset_to_cache(libdap::DDS *dds, const std::string &resourceId, const std::string &constraint,
101 const std::string &cache_file_name);
102
103 libdap::DDS *load_from_cache(const std::string &resource_id, std::string &cache_file_name);
104
105 friend class FunctionResponseCacheTest;
106 friend class StoredResultTest;
107
108protected:
123 BESDapFunctionResponseCache(const std::string &cache_dir, const std::string &prefix, unsigned long long size) :
124 BESFileLockingCache(cache_dir, prefix, size)
125 {
126 }
127
128public:
129 static const std::string PATH_KEY;
130 static const std::string PREFIX_KEY;
131 static const std::string SIZE_KEY;
132
133 static BESDapFunctionResponseCache *get_instance(const std::string &cache_dir, const std::string &prefix,
134 unsigned long long size);
135 static BESDapFunctionResponseCache *get_instance();
136
138 {
139 }
140
141 // If the DDS is in the cache and valid, return it otherwise, build the dds, cache it and return it.
142 // TODO cache_dataset() was too confusing, but get_or_... is not that great either
143 virtual libdap::DDS *get_or_cache_dataset(libdap::DDS *dds, const std::string &constraint);
144
145 virtual bool can_be_cached(libdap::DDS *dds, const std::string &constraint);
146
147 static string get_cache_dir_from_config();
148 static string get_cache_prefix_from_config();
149 static unsigned long get_cache_size_from_config();
150};
151
152#endif // _bes_dap_response_cache_h
Cache the results from server functions.
virtual libdap::DDS * get_or_cache_dataset(libdap::DDS *dds, const std::string &constraint)
Return a DDS loaded with data that can be serialized back to a client.
BESDapFunctionResponseCache(const std::string &cache_dir, const std::string &prefix, unsigned long long size)
Protected constructor that takes as arguments keys to the cache directory, file prefix,...