diff options
author | randomdan <randomdan@localhost> | 2011-08-31 21:48:04 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-08-31 21:48:04 +0000 |
commit | c6375740de642a3c954fe19614fbe55e1c8d2c9c (patch) | |
tree | 77abf662b898321a61058fb0a0da603e336bcad9 /project2/common/cache.cpp | |
parent | Adds RDBMS table caching solution (diff) | |
download | project2-c6375740de642a3c954fe19614fbe55e1c8d2c9c.tar.bz2 project2-c6375740de642a3c954fe19614fbe55e1c8d2c9c.tar.xz project2-c6375740de642a3c954fe19614fbe55e1c8d2c9c.zip |
The big reshuffle
Diffstat (limited to 'project2/common/cache.cpp')
-rw-r--r-- | project2/common/cache.cpp | 42 |
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); + } + } +} + |