summaryrefslogtreecommitdiffstats
path: root/src/uscxml/interpreter/InterpreterImpl.cpp
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-01-08 21:59:18 (GMT)
committerStefan Radomski <github@mintwerk.de>2017-01-08 21:59:18 (GMT)
commit030f3b483f54dbef6e164194a1771ef5b346312b (patch)
tree3f5b949b5ffed83d0b41a95d9fd3cfafd17cab2d /src/uscxml/interpreter/InterpreterImpl.cpp
parent1ab8b9a0dcaa131b8cccc735a1794ce39b351715 (diff)
downloaduscxml-030f3b483f54dbef6e164194a1771ef5b346312b.zip
uscxml-030f3b483f54dbef6e164194a1771ef5b346312b.tar.gz
uscxml-030f3b483f54dbef6e164194a1771ef5b346312b.tar.bz2
Support for caching values on filesystem
Use USCXML_NOCACHE_FILES=YES to prevent, I will make this a build flag
Diffstat (limited to 'src/uscxml/interpreter/InterpreterImpl.cpp')
-rw-r--r--src/uscxml/interpreter/InterpreterImpl.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp
index 43059bf..8762b95 100644
--- a/src/uscxml/interpreter/InterpreterImpl.cpp
+++ b/src/uscxml/interpreter/InterpreterImpl.cpp
@@ -27,11 +27,13 @@
#include "uscxml/messages/Event.h"
#include "uscxml/util/String.h"
#include "uscxml/util/Predicates.h"
+#include "uscxml/util/MD5.hpp"
#include "uscxml/plugins/InvokerImpl.h"
#include "uscxml/interpreter/Logging.h"
#include <iostream>
+#include <fstream>
#include <assert.h>
#include <algorithm>
@@ -108,6 +110,15 @@ InterpreterImpl::~InterpreterImpl() {
// assert(_invokers.size() == 0);
// ::xercesc_3_1::XMLPlatformUtils::Terminate();
+ if (!envVarIsTrue("USCXML_NOCACHE_FILES")) {
+ // save our cache
+ std::string sharedTemp = URL::getTempDir(true);
+ std::ofstream dataFS(sharedTemp + PATH_SEPERATOR + md5(_baseURL) + ".uscxml.cache");
+ if (dataFS) {
+ dataFS << _cache;
+ dataFS.close();
+ }
+ }
}
void InterpreterImpl::cancel() {
@@ -159,7 +170,6 @@ SCXML_STOP_SEARCH:
_binding = (HAS_ATTR(_scxml, "binding") && iequals(ATTR(_scxml, "binding"), "late") ? LATE : EARLY);
}
-
}
void InterpreterImpl::init() {
@@ -169,6 +179,33 @@ void InterpreterImpl::init() {
setupDOM();
+ if (!envVarIsTrue("USCXML_NOCACHE_FILES")) {
+ // try to open chached data from resource directory
+ std::string sharedTemp = URL::getTempDir(true);
+ std::ifstream dataFS(sharedTemp + PATH_SEPERATOR + md5(_baseURL) + ".uscxml.cache");
+ if (dataFS.is_open()) {
+ std::string cacheStr((std::istreambuf_iterator<char>(dataFS)),
+ std::istreambuf_iterator<char>());
+ _cache = Data::fromJSON(cacheStr);
+ }
+
+ // get md5 of current document
+ std::stringstream ss;
+ ss << *_document;
+ _md5 = md5(ss.str());
+
+ if (_cache.compound.find("InterpreterImpl") != _cache.compound.end() &&
+ _cache.compound["InterpreterImpl"].compound.find("md5") != _cache.compound["InterpreterImpl"].compound.end() &&
+ _cache.compound["InterpreterImpl"].compound["md5"].atom != _md5) {
+
+ // that's not our cache!
+ _cache.clear();
+ }
+
+ _cache.compound["InterpreterImpl"].compound["baseURL"] = Data(std::string(_baseURL));
+ _cache.compound["InterpreterImpl"].compound["md5"] = Data(_md5);
+ }
+
// register io processors
std::map<std::string, IOProcessorImpl*> ioProcs = _factory->getIOProcessors();
for (auto ioProcIter = ioProcs.begin(); ioProcIter != ioProcs.end(); ioProcIter++) {