summaryrefslogtreecommitdiff
path: root/project2/common/cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/common/cache.cpp')
-rw-r--r--project2/common/cache.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/project2/common/cache.cpp b/project2/common/cache.cpp
new file mode 100644
index 0000000..1dc435f
--- /dev/null
+++ b/project2/common/cache.cpp
@@ -0,0 +1,42 @@
+#include "cache.h"
+#include "rowSet.h"
+#include "rowProcessor.h"
+#include "logger.h"
+#include <boost/foreach.hpp>
+
+Cache::Cache(const xmlpp::Element * p) :
+ IHaveParameters(p),
+ SourceObject(p),
+ inherit(p->get_attribute_value("inherit") != "false")
+{
+}
+
+bool Cache::checkAndExecute(const Glib::ustring & n, const Glib::ustring & f, const RowProcessor * rp)
+{
+ RowSetCPtr cached = getCachedRowSet(n, f, rp);
+ if (cached) {
+ try {
+ Logger()->messagef(LOG_ERR, "Executing from cache");
+ cached->execute(f, rp);
+ return true;
+ }
+ catch (...) {
+ Logger()->messagef(LOG_WARNING, "Cache failed");
+ }
+ }
+ return false;
+}
+
+void
+Cache::applyKeys(const boost::function2<void, const std::string &, const VariableType &> & f, const IHaveParameters * ps) const
+{
+ BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, allParameters()) {
+ f(p.first, p.second);
+ }
+ if (inherit) {
+ BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, ps->allParameters()) {
+ f(p.first, p.second);
+ }
+ }
+}
+