bes  Updated for version 3.17.0
BESDapResponseCache.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2013 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #ifndef _bes_dap_response_cache_h
26 #define _bes_dap_response_cache_h
27 
28 #include <string>
29 #include "BESFileLockingCache.h"
30 
32 
33 namespace libdap {
34 class DDS;
35 class ConstraintEvaluator;
36 class BaseTypeFactory;
37 }
38 
45 private:
46 
47  static BESDapResponseCache *d_instance;
48  static void delete_instance()
49  {
50  delete d_instance;
51  d_instance = 0;
52  }
53 
56 
58 
59  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
60  void read_data_from_cache(const string &cache_file_name/*FILE *data*/, libdap::DDS *fdds);
61  libdap::DDS *get_cached_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory,
62  const std::string &dataset);
63 
64  friend class ResponseCacheTest;
65  friend class StoredResultTest;
66 
67 protected:
68 
82  BESDapResponseCache(const string &cache_dir, const string &prefix, unsigned long long size) :
83  BESFileLockingCache(cache_dir, prefix, size)
84  {
85  }
86 
87 public:
88  static const string PATH_KEY;
89  static const string PREFIX_KEY;
90  static const string SIZE_KEY;
91 
92  static BESDapResponseCache *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
93  static BESDapResponseCache *get_instance();
94 
95  virtual ~BESDapResponseCache()
96  {
97  }
98 
99  // If the DDS is in the cache and valid, return it otherwise, build the dds, cache it and return it.
100  virtual libdap::DDS *cache_dataset(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb,
101  libdap::ConstraintEvaluator *eval, std::string &cache_token);
102 
103  static string getCacheDirFromConfig();
104  static string getCachePrefixFromConfig();
105  static unsigned long getCacheSizeFromConfig();
106 };
107 
108 #endif // _bes_dap_response_cache_h
Implementation of a caching mechanism for compressed data. This cache uses simple advisory locking fo...
BESDapResponseCache(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.