bes  Updated for version 3.20.6
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 
35 namespace libdap {
36 class DDS;
37 class ConstraintEvaluator;
38 class BaseTypeFactory;
39 }
40 
73 private:
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 
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(istream &cached_data);
99 
100  libdap::DDS *write_dataset_to_cache(libdap::DDS *dds, const string &resourceId, const string &constraint,
101  const string &cache_file_name);
102 
103  libdap::DDS *load_from_cache(const string &resource_id, string &cache_file_name);
104 
105  friend class FunctionResponseCacheTest;
106  friend class StoredResultTest;
107 
108 protected:
123  BESDapFunctionResponseCache(const string &cache_dir, const string &prefix, unsigned long long size) :
124  BESFileLockingCache(cache_dir, prefix, size)
125  {
126  }
127 
128 public:
129  static const string PATH_KEY;
130  static const string PREFIX_KEY;
131  static const string SIZE_KEY;
132 
133  static BESDapFunctionResponseCache *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
134  static BESDapFunctionResponseCache *get_instance();
135 
136  virtual ~BESDapFunctionResponseCache()
137  {
138  }
139 
140  // If the DDS is in the cache and valid, return it otherwise, build the dds, cache it and return it.
141  // TODO cache_dataset() was too confusing, but get_or_... is not that great either
142  virtual libdap::DDS *get_or_cache_dataset(libdap::DDS *dds, const std::string &constraint);
143 
144  virtual bool can_be_cached(libdap::DDS *dds, const std::string &constraint);
145 
146  static string get_cache_dir_from_config();
147  static string get_cache_prefix_from_config();
148  static unsigned long get_cache_size_from_config();
149 };
150 
151 #endif // _bes_dap_response_cache_h
BaseTypeFactory
BESDapFunctionResponseCache::get_or_cache_dataset
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.
Definition: BESDapFunctionResponseCache.cc:320
libdap
Definition: BESDapFunctionResponseCache.h:35
BESFileLockingCache
Implementation of a caching mechanism for compressed data.
Definition: BESFileLockingCache.h:85
BESDapResponseBuilder
Definition: BESDapResponseBuilder.h:53
BESDapFunctionResponseCache
Cache the results from server functions.
Definition: BESDapFunctionResponseCache.h:72
BESDapFunctionResponseCache::BESDapFunctionResponseCache
BESDapFunctionResponseCache(const string &cache_dir, const string &prefix, unsigned long long size)
Protected constructor that takes as arguments keys to the cache directory, file prefix,...
Definition: BESDapFunctionResponseCache.h:123