Page Cache

This commit is contained in:
2016-10-15 00:25:57 +08:00
parent 7b8348be37
commit 96c9d608c2
2 changed files with 87 additions and 5 deletions

View File

@@ -1,10 +1,11 @@
"use strict";
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var CondStream = cl.load( "botanss.utils.CondStream" );
const cl = global.botanLoader;
const Dragonfly = global.Dragonfly;
const PageCache = global.botanPageCache;
var FatalError = cl.load( "botanss.errors.FatalError" );
const CondStream = cl.load( "botanss.utils.CondStream" );
const FatalError = cl.load( "botanss.errors.FatalError" );
class WebFrame
{
@@ -108,7 +109,7 @@ class WebFrame
this.handlers[ name ] = method.bind( this );
}
plantResult()
plantResult( cache, ttl )
{
if( this.planted ) return;
@@ -124,6 +125,8 @@ class WebFrame
this.HTTP.response.write( this.result );
this.HTTP.response.end();
Dragonfly.Debug( "Result Planted" );
this.__storeCache( cache, ttl );
}
// Release resources
@@ -133,6 +136,20 @@ class WebFrame
}
}
__storeCache( cache, ttl )
{
if( cache && PageCache )
{
if( ttl == undefined ) ttl = 30;
PageCache.store(
this.HTTP.request.raw
, this.HTTP.response
, this.result
, ttl
);
}
}
// This won't handle path exists
// throwing an error is better than handling it
// Need to handle it somewhere else