From 3e8b42b3c485f19c758cf195a249ab9657032ee2 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 18 Jul 2012 01:10:22 +0000 Subject: Regig output flow in CGI app engine to serve cached content when first created, addresses bug23 Minor tweak to file presenter cache to allow reopening of just generated content --- project2/cgi/cgiAppEngine.cpp | 26 ++++++++++++++++++-------- project2/files/presenterCache.cpp | 11 ++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index d9948e4..28600b3 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -107,11 +107,6 @@ CgiApplicationEngine::process() const if (TransformSourcePtr ts = currentStage.get<2>()) { TransformSourcePtr final = finalTransformSource(ts); ScopeObject emptyFinal([final] { final->clearTargets(); }); - final->addTarget(new CgiResult(header, IO, - rs && rs->outputOptions ? rs->outputOptions->Encoding().as() : OutputOptions::encoding), NULL); - BOOST_FOREACH(const PresenterCachePtr & p, rs->caches) { - final->addTarget(p, NULL); - } boost::shared_ptr ddd; ostreamWrapper * osw = NULL; ScopeObject removeDdd([ts, &osw] { if (osw) { ts->removeTarget(osw); } }); @@ -124,10 +119,25 @@ CgiApplicationEngine::process() const ddd.reset(); } } - ts->doTransforms(); - BOOST_FOREACH(const PresenterCachePtr & p, rs->caches) { - p->flushCache(); + if (outputCachingActive) { + BOOST_FOREACH(const PresenterCachePtr & p, rs->caches) { + final->addTarget(p, NULL); + } + ts->doTransforms(); + BOOST_FOREACH(const PresenterCachePtr & p, rs->caches) { + p->flushCache(); + } + if (rs->caches.front()->check(0)) { + ScopeObject emptyFinal([rs] { rs->caches.front()->clearTargets(); }); + rs->caches.front()->addTarget(new CgiResult(header, IO, + rs && rs->outputOptions ? rs->outputOptions->Encoding().as() : OutputOptions::encoding), NULL); + rs->caches.front()->doTransforms(); + return; + } } + final->addTarget(new CgiResult(header, IO, + rs && rs->outputOptions ? rs->outputOptions->Encoding().as() : OutputOptions::encoding), NULL); + ts->doTransforms(); } else { header->render(IO); diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 90c2bc9..6c21580 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -104,11 +104,12 @@ class FilePresenterCache : public PresenterCache { f = openCacheFile(key); safesys(-1, fstat(*f, &st)); } - if ((st.st_mtime < (time(NULL) - FilePresenterCache::CacheLife)) || (st.st_mtime < scriptMtime)) { - unlink(getCacheFile().string().c_str()); - openCaches.erase(key); - f.reset(); - return false; + if (scriptMtime != 0) { + if ((st.st_mtime < (time(NULL) - FilePresenterCache::CacheLife)) || (st.st_mtime < scriptMtime)) { + unlink(getCacheFile().string().c_str()); + openCaches.erase(key); + return false; + } } myCache = f; return true; -- cgit v1.2.3