summaryrefslogtreecommitdiff
path: root/project2/common/cache.cpp
blob: ff9f41f397406f28d79d22a30e8833e45aa45312 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <pch.hpp>
#include "cache.h"
#include "rowSet.h"
#include "rowProcessor.h"
#include "logger.h"
#include <boost/foreach.hpp>
#include <glibmm/exception.h>

Cache::Cache(ScriptNodePtr p) :
	IHaveParameters(p),
	SourceObject(p),
	inherit(p->value("inherit", true).as<bool>())
{
}

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_DEBUG, "Executing from cache '%s'", name.c_str());
			cached->execute(f, rp);
			return true;
		}
		catch (const Glib::Exception & e) {
			Logger()->messagef(LOG_WARNING, "Cache failed (%s)", e.what().c_str());
		}
		catch (const std::exception & e) {
			Logger()->messagef(LOG_WARNING, "Cache failed (%s)", e.what());
		}
		catch (...) {
			Logger()->message(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);
		}
	}
}