bes  Updated for version 3.17.0
BESStoredDapResultCache.h
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_store_result_cache_h
27 #define _bes_store_result_cache_h
28 
29 #include <string>
30 
31 #include <DapXmlNamespaces.h>
32 #include <DMR.h>
33 #include "BESFileLockingCache.h"
34 
36 
37 // using the namespace in the forward declaration works with older g++ versions
38 // because they are sensible and not literal. It should not work; the decl class
39 // libdap::BaseType; tells the compiler go look i the 'libdap' namespace for 'BaseType'
40 // but _while it's compiling this file_ there is no 'libdap' namespace. So we make one.
41 namespace libdap {
42  class DDS;
43  class ConstraintEvaluator;
44  class BaseTypeFactory;
45 }
46 
53 {
54 private:
55 
56  static BESStoredDapResultCache *d_instance;
57  static void delete_instance() { delete d_instance; d_instance = 0; }
58 
59  string d_storedResultsSubdir;
60  string d_dataRootDir;
61  string d_resultFilePrefix;
62  unsigned long d_maxCacheSize;
63 
67 
68  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
69  bool read_dap2_data_from_cache(const string &cache_file_name/*FILE *data*/, libdap::DDS *fdds);
70  bool read_dap4_data_from_cache(const string &cache_file_name, libdap::DMR *dmr);
71 
72  friend class StoredDap2ResultTest;
73  friend class StoredDap4ResultTest;
74  friend class ResponseBuilderTest;
75 
76  string get_stored_result_local_id(const string &dataset, const string &ce, libdap::DAPVersion version);
77 
78  string getBesDataRootDirFromConfig();
79  string getSubDirFromConfig();
80  string getResultPrefixFromConfig();
81  unsigned long getCacheSizeFromConfig();
82 
83 protected:
84 
85  BESStoredDapResultCache(const string &data_root_dir, const string &stored_results_subdir, const string &prefix, unsigned long long size);
86 
87 public:
88  static const string SUBDIR_KEY;
89  static const string PREFIX_KEY;
90  static const string SIZE_KEY;
91 
92  static BESStoredDapResultCache *get_instance(const string &bes_catalog_root_dir, const string &stored_results_subdir, const string &prefix, unsigned long long size);
93  static BESStoredDapResultCache *get_instance();
94 
95  // static string assemblePath(const string &firstPart, const string &secondPart, bool addLeadingSlash = false);
96 
97  libdap::DDS *get_cached_dap2_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset);
98  libdap::DMR *get_cached_dap4_data(const string &cache_file_name, libdap::D4BaseTypeFactory *factory, const string &filename);
99 
100  virtual ~BESStoredDapResultCache() {
101  // delete_instance();
102  }
103 
104  // Store the passed DDS to disk as a serialized DAP2 object.
105  virtual string store_dap2_result(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb,
106  libdap::ConstraintEvaluator *eval);
107 
108  // Store the passed DMR to disk as a serialized DAP4 object.
109  virtual string store_dap4_result(libdap::DMR &dmr, const string &constraint, BESDapResponseBuilder *rb);
110 
111  // virtual void unlock_and_close(const std::string &cache_token);
112 
113  // Overrides parent
114  // virtual string get_cache_file_name(const string &src, bool mangle = false);
115 
116 };
117 
118 #endif // _bes_store_result_cache_h
Implementation of a caching mechanism for compressed data. This cache uses simple advisory locking fo...