From 3c226d5b1b7e64506496436cda613c3d5083f3dd Mon Sep 17 00:00:00 2001 From: Omar Siam Date: Fri, 7 Jun 2024 15:26:24 +0200 Subject: [PATCH] Allow for a small time in cache but then only revalidate This should use caches a little but only fetch the whole config if it changed as for example in the test. --- cypress/e2e/homepage_config.cy.js | 67 +++++++++++++++++++++ cypress/e2e/homepage_config_a_tunisia.cy.js | 34 ----------- cypress/e2e/homepage_config_b_default.cy.js | 34 ----------- vicav.xqm | 4 +- 4 files changed, 69 insertions(+), 70 deletions(-) create mode 100644 cypress/e2e/homepage_config.cy.js delete mode 100644 cypress/e2e/homepage_config_a_tunisia.cy.js delete mode 100644 cypress/e2e/homepage_config_b_default.cy.js diff --git a/cypress/e2e/homepage_config.cy.js b/cypress/e2e/homepage_config.cy.js new file mode 100644 index 0000000..ef4b474 --- /dev/null +++ b/cypress/e2e/homepage_config.cy.js @@ -0,0 +1,67 @@ +describe('Home page', function() { + const BASEX_ROOT = Cypress.env('BASEX_ROOT') || '/app/.heroku/basex' + const BASEX_PWD = Cypress.env('BASEX_admin_pw') || 'admin' + + it('should show Tunisia with different config', function() { + cy.exec(`${BASEX_ROOT}/bin/basexclient -Uadmin -P${BASEX_PWD} -c "OPEN vicav_projects; REPLACE vicav.xml ${Cypress.config()['fileServerFolder']}/fixtures/vicav_projects/map.xml"`) + cy.request({ + method: 'PUT', + url: 'http://localhost:8984/vicav/project', + headers: {'Accept': 'application/json'} + }).as('refreshConfig') + cy.get('@refreshConfig').should((response) => { + expect(response.status).to.equal(200) + expect(response.body.projectConfig).to.exist + }) + cy.request({ + method: 'GET', + url: 'http://localhost:8984/vicav/project', + headers: {'Accept': 'application/json'} + }).as('config') + cy.get('@config').should((response) => { + expect(response.status).to.equal(200) + expect(response.body.projectConfig).to.exist + expect(response.body.projectConfig.cached).to.be.true + expect(response.body.ETag).to.exist + expect(response.headers['cache-control']).to.contain('max-age=2') + expect(response.headers['cache-control']).to.contain('must-revalidate') + }) + cy.visit('http://localhost:8984/vicav/') + cy.get('#cookie-overlay').should('be.visible') + cy.get('.cookie-accept-btn').click() + cy.get('#cookie-overlay').should('not.be.visible') + cy.get('img.leaflet-marker-icon') // Wait until the initial markers appear. + cy.get('img[alt^="Khorasan"]').should('not.be.visible'); + cy.wait(1000) // Wait for the cache to expire + }) + + it('should show whole Middle-East by deafult', function() { + cy.exec(`${BASEX_ROOT}/bin/basexclient -Uadmin -P${BASEX_PWD} -c "OPEN vicav_projects; REPLACE vicav.xml ${Cypress.config()['fileServerFolder']}/fixtures/vicav_projects/vicav.xml"`) + cy.request({ + method: 'PUT', + url: 'http://localhost:8984/vicav/project', + headers: {'Accept': 'application/json'} + }).as('refreshConfig') + cy.get('@refreshConfig').should((response) => { + expect(response.status).to.equal(200) + expect(response.body.projectConfig).to.exist + }) + cy.request({ + method: 'GET', + url: 'http://localhost:8984/vicav/project', + headers: {'Accept': 'application/json'} + }).as('config') + cy.get('@config').should((response) => { + expect(response.status).to.equal(200) + expect(response.body.projectConfig).to.exist + expect(response.body.projectConfig.cached).to.be.true + expect(response.body.ETag).to.exist + }) + cy.visit('http://localhost:8984/vicav/') + cy.get('#cookie-overlay').should('be.visible') + cy.get('.cookie-accept-btn').click() + cy.get('#cookie-overlay').should('not.be.visible') + cy.get('img.leaflet-marker-icon') // Wait until the initial markers appear. + cy.get('img[alt^="Khorasan"]').should('be.visible'); + }) +}) \ No newline at end of file diff --git a/cypress/e2e/homepage_config_a_tunisia.cy.js b/cypress/e2e/homepage_config_a_tunisia.cy.js deleted file mode 100644 index 53150ff..0000000 --- a/cypress/e2e/homepage_config_a_tunisia.cy.js +++ /dev/null @@ -1,34 +0,0 @@ -describe('Home page', function() { - const BASEX_ROOT = Cypress.env('BASEX_ROOT') || '/app/.heroku/basex' - const BASEX_PWD = Cypress.env('BASEX_admin_pw') || 'admin' - - it('should show Tunisia with different config', function() { - cy.exec(`${BASEX_ROOT}/bin/basexclient -Uadmin -P${BASEX_PWD} -c "OPEN vicav_projects; REPLACE vicav.xml ${Cypress.config()['fileServerFolder']}/fixtures/vicav_projects/map.xml"`) - cy.request({ - method: 'PUT', - url: 'http://localhost:8984/vicav/project', - headers: {'Accept': 'application/json'} - }).as('refreshConfig') - cy.get('@refreshConfig').should((response) => { - expect(response.status).to.equal(200) - expect(response.body.projectConfig).to.exist - }) - cy.request({ - method: 'GET', - url: 'http://localhost:8984/vicav/project', - headers: {'Accept': 'application/json'} - }).as('config') - cy.get('@config').should((response) => { - expect(response.status).to.equal(200) - expect(response.body.projectConfig).to.exist - expect(response.body.projectConfig.cached).to.be.true - expect(response.body.ETag).to.exist - }) - cy.visit('http://localhost:8984/vicav/') - cy.get('#cookie-overlay').should('be.visible') - cy.get('.cookie-accept-btn').click() - cy.get('#cookie-overlay').should('not.be.visible') - cy.get('img.leaflet-marker-icon') // Wait until the initial markers appear. - cy.get('img[alt^="Khorasan"]').should('not.be.visible'); - }) -}) \ No newline at end of file diff --git a/cypress/e2e/homepage_config_b_default.cy.js b/cypress/e2e/homepage_config_b_default.cy.js deleted file mode 100644 index dfcb7c0..0000000 --- a/cypress/e2e/homepage_config_b_default.cy.js +++ /dev/null @@ -1,34 +0,0 @@ -describe('Home page', function() { - const BASEX_ROOT = Cypress.env('BASEX_ROOT') || '/app/.heroku/basex' - const BASEX_PWD = Cypress.env('BASEX_admin_pw') || 'admin' - - it('should show whole Middle-East by deafult', function() { - cy.exec(`${BASEX_ROOT}/bin/basexclient -Uadmin -P${BASEX_PWD} -c "OPEN vicav_projects; REPLACE vicav.xml ${Cypress.config()['fileServerFolder']}/fixtures/vicav_projects/vicav.xml"`) - cy.request({ - method: 'PUT', - url: 'http://localhost:8984/vicav/project', - headers: {'Accept': 'application/json'} - }).as('refreshConfig') - cy.get('@refreshConfig').should((response) => { - expect(response.status).to.equal(200) - expect(response.body.projectConfig).to.exist - }) - cy.request({ - method: 'GET', - url: 'http://localhost:8984/vicav/project', - headers: {'Accept': 'application/json'} - }).as('config') - cy.get('@config').should((response) => { - expect(response.status).to.equal(200) - expect(response.body.projectConfig).to.exist - expect(response.body.projectConfig.cached).to.be.true - expect(response.body.ETag).to.exist - }) - cy.visit('http://localhost:8984/vicav/') - cy.get('#cookie-overlay').should('be.visible') - cy.get('.cookie-accept-btn').click() - cy.get('#cookie-overlay').should('not.be.visible') - cy.get('img.leaflet-marker-icon') // Wait until the initial markers appear. - cy.get('img[alt^="Khorasan"]').should('be.visible'); - }) -}) \ No newline at end of file diff --git a/vicav.xqm b/vicav.xqm index ed96a37..9da7c6b 100644 --- a/vicav.xqm +++ b/vicav.xqm @@ -114,13 +114,13 @@ function vicav:project_config() { , map:merge((cors:header(()), vicav:return_content_header(), map{ 'X-UA-Compatible': 'IE=11' - , 'Cache-Control': 'max-age=3600,public' + , 'Cache-Control': 'public, max-age=2, must-revalidate' , 'ETag': $hash }))) else api-problem:or_result (prof:current-ns(), vicav:_project_config#0, [], map:merge((cors:header(()), vicav:return_content_header(), map{ 'X-UA-Compatible': 'IE=11' - , 'Cache-Control': 'max-age=3600,public' + , 'Cache-Control': 'public, max-age=2, must-revalidate' , 'ETag': $hash })) )