diff --git a/example/app.js b/example/app.js index 1b14dbab..c94f4021 100644 --- a/example/app.js +++ b/example/app.js @@ -2,9 +2,9 @@ let data = {} data.definition = 'BranchNodeRnd.gh' data.inputs = { - 'Length':document.getElementById('length').value, - 'Count':document.getElementById('count').value, - 'Radius':document.getElementById('radius').value + 'Count':document.getElementById('count').valueAsNumber, + 'Radius':document.getElementById('radius').valueAsNumber, + 'Length':document.getElementById('length').valueAsNumber } // set this to the target appserver url @@ -30,11 +30,15 @@ async function compute(){ let t0 = performance.now() const timeComputeStart = t0 + console.log(data.inputs) + const request = { 'method':'POST', 'body': JSON.stringify(data), 'headers': {'Content-Type': 'application/json'} } + + let response = await fetch(url, request) // Request finished. Do processing here. @@ -95,9 +99,9 @@ function onSliderChange () { // get slider values data.inputs = { - 'Length':document.getElementById('length').value, - 'Count':document.getElementById('count').value, - 'Radius':document.getElementById('radius').value + 'Count':document.getElementById('count').valueAsNumber, + 'Radius':document.getElementById('radius').valueAsNumber, + 'Length':document.getElementById('length').valueAsNumber } compute() } diff --git a/example/index.html b/example/index.html index fe6fd3e0..51fc3e13 100644 --- a/example/index.html +++ b/example/index.html @@ -38,15 +38,15 @@
- +
- +
- +
diff --git a/example/warm.html b/example/warm.html new file mode 100644 index 00000000..5ea17038 --- /dev/null +++ b/example/warm.html @@ -0,0 +1,112 @@ + + + + + + + + Compute RestHopper Test + + + +
+ + + diff --git a/package.json b/package.json index 0e0433fb..468e4694 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mcneel/compute.rhino3d.appserver", - "version": "0.1.8", + "version": "0.1.9", "keywords": [ "node.js", "expressjs", diff --git a/routes/solve.js b/routes/solve.js index a05ee8a4..544263a0 100644 --- a/routes/solve.js +++ b/routes/solve.js @@ -66,16 +66,21 @@ function collectParams (req, res, next){ function checkCache (req, res, next){ - res.locals.cacheKey = JSON.stringify(res.locals.params) + const key = {} + key.definition = { 'name': res.locals.params.definition.name, 'id': res.locals.params.definition.id } + key.inputs = res.locals.params.inputs + res.locals.cacheKey = JSON.stringify(key) res.locals.cacheResult = null if(mc === null){ // use node cache + //console.log('using node-cache') const result = cache.get(res.locals.cacheKey) res.locals.cacheResult = result !== undefined ? result : null next() } else { // use memcached + //console.log('using memcached') if(mc !== null) { mc.get(res.locals.cacheKey, function(err, val) { if(err == null) { @@ -104,12 +109,14 @@ function commonSolve (req, res, next){ if(res.locals.cacheResult !== null) { //send + //console.log(res.locals.cacheResult) const timespanPost = Math.round(performance.now() - timePostStart) res.setHeader('Server-Timing', `cacheHit;dur=${timespanPost}`) res.send(res.locals.cacheResult) return } else { //solve + //console.log('solving') // set parameters let trees = [] if(res.locals.params.inputs !== undefined) { //TODO: handle no inputs