OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESDapResponseCache.h
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2013 OPeNDAP, Inc.
8 // Author: 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_response_cache_h
27 #define _bes_dap_response_cache_h
28 
29 #include <string>
30 #include "BESFileLockingCache.h"
31 
32 
34 
35 namespace libdap {
36  class DDS;
37  class ConstraintEvaluator;
38  class BaseTypeFactory;
39 }
40 
47 {
48 private:
49 
50  static BESDapResponseCache * d_instance;
51 
54 
56 
57  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
58  void read_data_from_cache(const string &cache_file_name/*FILE *data*/, libdap::DDS *fdds);
59  libdap::DDS *get_cached_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset);
60 
61  friend class ResponseCacheTest;
62  friend class StoredResultTest;
63 
64  static void delete_instance();
65 
66 protected:
67 
68  BESDapResponseCache(const string &cache_dir, const string &prefix, unsigned long long size);
69 
70 
71 public:
72  static const string PATH_KEY;
73  static const string PREFIX_KEY;
74  static const string SIZE_KEY;
75 
76  static BESDapResponseCache *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
78 
79  virtual ~BESDapResponseCache() {}
80 
81 #if 0
82  // If the DDS is in the cache and valid, return it
83  virtual libdap::DDS *read_dataset(const std::string &filename, const std::string &constraint, std::string &cache_token);
84 #endif
85 
86  // If the DDS is in the cache and valid, return it otherwise, build the dds, cache it and return it.
87  virtual libdap::DDS *cache_dataset(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb,
88  libdap::ConstraintEvaluator *eval, std::string &cache_token);
89 
90  // virtual void unlock_and_close(const std::string &cache_token);
91 
92  static string getCacheDirFromConfig();
93  static string getCachePrefixFromConfig();
94  static unsigned long getCacheSizeFromConfig();
95 
96 };
97 
98 #endif // _bes_dap_response_cache_h
static unsigned long getCacheSizeFromConfig()
virtual libdap::DDS * cache_dataset(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb, libdap::ConstraintEvaluator *eval, std::string &cache_token)
Get the cached DDS object.
static BESDapResponseCache * get_instance()
Get the default instance of the BESDapResponseCache object.
This class is used to cache DAP2 response objects.
Implementation of a caching mechanism for compressed data.
static const string SIZE_KEY
friend class StoredResultTest
static string getCacheDirFromConfig()
static string getCachePrefixFromConfig()
This class is used to build responses for/by the BES.
static const string PREFIX_KEY
friend class ResponseCacheTest
static const string PATH_KEY