bes  Updated for version 3.17.4
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 BESDapFunctionResponseCache *d_instance;
75 
79  static void delete_instance() {
80  delete d_instance;
81  d_instance = 0;
82  }
83 
91 
92  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
93 
94  std::string get_resource_id(libdap::DDS *dds, const std::string &constraint);
95  std::string get_hash_basename(const std::string &resource_id);
96 
97  libdap::DDS *read_cached_data(istream &cached_data);
98 
99  libdap::DDS *write_dataset_to_cache(libdap::DDS *dds, const string &resourceId, const string &constraint,
100  const string &cache_file_name);
101 
102  libdap::DDS *load_from_cache(const string &resource_id, string &cache_file_name);
103 
104  friend class FunctionResponseCacheTest;
105  friend class StoredResultTest;
106 
107 protected:
122  BESDapFunctionResponseCache(const string &cache_dir, const string &prefix, unsigned long long size) :
123  BESFileLockingCache(cache_dir, prefix, size)
124  {
125  }
126 
127 public:
128  static const string PATH_KEY;
129  static const string PREFIX_KEY;
130  static const string SIZE_KEY;
131 
132  static BESDapFunctionResponseCache *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
133  static BESDapFunctionResponseCache *get_instance();
134 
135  virtual ~BESDapFunctionResponseCache()
136  {
137  }
138 
139  // If the DDS is in the cache and valid, return it otherwise, build the dds, cache it and return it.
140  // TODO cache_dataset() was too confusing, but get_or_... is not that great either
141  virtual libdap::DDS *get_or_cache_dataset(libdap::DDS *dds, const std::string &constraint);
142 
143  virtual bool can_be_cached(libdap::DDS *dds, const std::string &constraint);
144 
145  static string get_cache_dir_from_config();
146  static string get_cache_prefix_from_config();
147  static unsigned long get_cache_size_from_config();
148 };
149 
150 #endif // _bes_dap_response_cache_h
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, and size of the cache to be looked up a configuration file.
Implementation of a caching mechanism for compressed data. This cache uses simple advisory locking fo...
Cache the results from server functions.