OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESStoredDapResultCache.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_store_result_cache_h
27 #define _bes_store_result_cache_h
28 
29 #include <string>
30 #include "BESFileLockingCache.h"
31 
33 
34 // using the namespace in the forward declaration works with older g++ versions
35 // because they are sensible and not literal. It should not work; the decl class
36 // libdap::BaseType; tells the compiler go look i the 'libdap' namespace for 'BaseType'
37 // but _while it's compiling this file_ there is no 'libdap' namespace. So we make one.
38 namespace libdap {
39  class DDS;
40  class ConstraintEvaluator;
41  class BaseTypeFactory;
42 }
43 
50 {
51 private:
52 
53  static BESStoredDapResultCache * d_instance;
54 
57 
59 
60  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
61  void read_data_from_cache(const string &cache_file_name/*FILE *data*/, libdap::DDS *fdds);
62  libdap::DDS *get_cached_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset);
63 
64  friend class StoredResultTest;
65 
66  static void delete_instance();
67 
68  string build_stored_result_file_name(const string &dataset, const string &ce);
69 
70 protected:
71 
72  BESStoredDapResultCache(const string &cache_dir, const string &prefix, unsigned long long size);
73 
74 
75 public:
76  static const string SUBDIR_KEY;
77  static const string PREFIX_KEY;
78  static const string SIZE_KEY;
79 
80  static BESStoredDapResultCache *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
82 
84 
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 getStoredResultsDirFromConfig();
93  static string getSubDirFromConfig();
94  static string getResultPrefixFromConfig();
95  static unsigned long getCacheSizeFromConfig();
96 
97  // Overrides parent
98  virtual string get_cache_file_name(const string &src, bool mangle = false);
99 
100 };
101 
102 #endif // _bes_store_result_cache_h
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.
virtual string get_cache_file_name(const string &src, bool mangle=false)
Build the name of file that will holds the uncompressed data from 'src' in the cache.
static string getStoredResultsDirFromConfig()
Implementation of a caching mechanism for compressed data.
static BESStoredDapResultCache * get_instance()
Get the default instance of the BESStoreResultCache object.
static const string SUBDIR_KEY
static const string PREFIX_KEY
static unsigned long getCacheSizeFromConfig()
This class is used to build responses for/by the BES.
This class is used to cache DAP2 response objects.