Skip to content

Commit

Permalink
Allow for a small time in cache but then only revalidate
Browse files Browse the repository at this point in the history
This should use caches a little but only fetch the whole config if it changed as for example in the test.
  • Loading branch information
simar0at committed Jun 7, 2024
1 parent 27ae42d commit 3c226d5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 70 deletions.
67 changes: 67 additions & 0 deletions cypress/e2e/homepage_config.cy.js
Original file line number Diff line number Diff line change
@@ -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');
})
})
34 changes: 0 additions & 34 deletions cypress/e2e/homepage_config_a_tunisia.cy.js

This file was deleted.

34 changes: 0 additions & 34 deletions cypress/e2e/homepage_config_b_default.cy.js

This file was deleted.

4 changes: 2 additions & 2 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ function vicav:project_config() {
</problem>,
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
}))
)
Expand Down

0 comments on commit 3c226d5

Please sign in to comment.