summaryrefslogtreecommitdiff
path: root/project2/common/cache.cpp
blob: f5edc43631d8ccc64edeceebdee1f554e7df184f (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
#include <pch.hpp>
#include "cache.h"
#include "rowSet.h"
#include "rowProcessor.h"
#include "logger.h"
#include <boost/foreach.hpp>

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 (...) {
			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);
		}
	}
}