TECA
The Toolkit for Extreme Climate Analysis
teca_indexed_dataset_cache.h
1 #ifndef teca_indexed_dataset_cache_h
2 #define teca_indexed_dataset_cache_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 
8 #include <string>
9 #include <vector>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_indexed_dataset_cache)
12 
13 /// Caches N datasets such that repeated requests for the same dataset are served from the cache
14 /**
15  * A cache storing up to N datasets. Datasets are identified using their
16  * request index. Repeated requests for the same dataset (ie same index) are
17  * served from the cache. When more than N unique datasets have been requested
18  * the cache is modified such that the least recently used dataset is replaced.
19  */
21 {
22 public:
23  TECA_ALGORITHM_STATIC_NEW(teca_indexed_dataset_cache)
24  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_indexed_dataset_cache)
25  TECA_ALGORITHM_CLASS_NAME(teca_indexed_dataset_cache)
27 
28  // report/initialize to/from Boost program options
29  // objects.
30  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
31  TECA_SET_ALGORITHM_PROPERTIES()
32 
33  /** @name max_cache_size
34  * Set the max number of datasets to cache.
35  */
36  ///@{
37  TECA_ALGORITHM_PROPERTY(unsigned long, max_cache_size)
38  ///@}
39 
40  /// clear any cached data.
41  void clear_cache();
42 
43  /** @name override_request_index
44  * When set the request is modified to always request index 0. This can be
45  * used to cache data that doesn't change.
46  */
47  ///@{
48  TECA_ALGORITHM_PROPERTY(int, override_request_index)
49  ///@}
50 
51 protected:
53 
54 private:
55 
56  std::vector<teca_metadata> get_upstream_request(
57  unsigned int port,
58  const std::vector<teca_metadata> &input_md,
59  const teca_metadata &request) override;
60 
61  const_p_teca_dataset execute(
62  unsigned int port,
63  const std::vector<const_p_teca_dataset> &input_data,
64  const teca_metadata &request) override;
65 
66 private:
67  unsigned long max_cache_size;
68  int override_request_index;
69 
70  struct internals_t;
71  internals_t *internals;
72 };
73 
74 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
Caches N datasets such that repeated requests for the same dataset are served from the cache.
Definition: teca_indexed_dataset_cache.h:21
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.