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, NULL).as<bool>())
{
}
bool Cache::checkAndExecute(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * p, const RowProcessorCallback & rp)
{
RowSetCPtr cached = getCachedRowSet(ec, n, f, p);
if (cached) {
try {
Logger()->messagebf(LOG_DEBUG, "Executing from cache '%s'", name);
cached->execute(f, rp, ec);
return true;
}
catch (const Glib::Exception & e) {
Logger()->messagebf(LOG_WARNING, "Cache failed (%s)", e.what());
}
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(ExecContext * ec, const KeyApplier & f, const IHaveParameters * ps) const
{
BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, allParameters()) {
f(p.first, p.second(ec));
}
if (inherit) {
BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, ps->allParameters()) {
f(p.first, p.second(ec));
}
}
}
|