Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache configuration not working correctly #15126

Closed
1 task done
sbrunecker opened this issue May 26, 2021 · 4 comments · Fixed by #15148
Closed
1 task done

Cache configuration not working correctly #15126

sbrunecker opened this issue May 26, 2021 · 4 comments · Fixed by #15148
Labels
area: bug 🐛 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: cache theme: java $100 https://www.jhipster.tech/bug-bounties/
Milestone

Comments

@sbrunecker
Copy link
Contributor

Overview of the issue

I am using jhipster-sample-app-gradle and started it with Spring profile prod. Most files are served with Cache-Control: no-store. It seems the only file where the cache configuration is working is i18n/en.json which is served with Cache-Control: max-age=126230400, public.

So I believe the issue is:

  • content of subfolders of static/content is not cached
  • the Angular application is not compiled to static/app anymore but directly to static/ while the cache configuration in StaticResourcesWebConfiguration still configures a policy for classpath:/static/app/
Motivation for or Use Case

Caching makes the application more performant.

Reproduce the error
  1. Clone jhipster-sample-app-gradle
  2. Start the database from src/main/docker/mysql.yml or configure h2 to start with prod profile
  3. Start the application with prod profile
  4. Go to http://localhost:8080/ and observe that only en.json is configured to be cached
Related issues

#11575

Suggest a Fix

With the following configuration more files have a cache control header set. However, this will also cache service-worker.js and I'm not sure if it's okay.

registry.addResourceHandler("/content/**", "/i18n/*")
    .addResourceLocations("classpath:/static/content/", "classpath:/static/i18n/")
    .setCacheControl(getCacheControl());
registry.addResourceHandler("/*.js")
    .addResourceLocations("classpath:/static/")
    .setCacheControl(getCacheControl());
JHipster Version(s)

7.0.1

JHipster configuration
JHipster Version(s)
jhipster-gradle-sample-application@0.0.1-SNAPSHOT C:\Users\stefan\projects\jhipster-sample-app-gradle
`-- generator-jhipster@7.0.1

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "baseName": "jhipsterGradleSampleApplication",
    "packageName": "io.github.jhipster.sample",
    "packageFolder": "io/github/jhipster/sample",
    "authenticationType": "session",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "prodDatabaseType": "mysql",
    "useCompass": false,
    "buildTool": "gradle",
    "rememberMeKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "searchEngine": false,
    "enableTranslation": true,
    "applicationType": "monolith",
    "testFrameworks": ["gatling", "protractor"],
    "languages": ["en"],
    "serverPort": 8080,
    "jhipsterVersion": "7.0.1",
    "enableSocialSignIn": false,
    "useSass": true,
    "jhiPrefix": "jhi",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "reactive": false,
    "otherModules": [],
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "clientTheme": "none",
    "blueprints": [],
    "embeddableLaunchScript": false,
    "creationTimestamp": 1577000956924,
    "skipUserManagement": false,
    "withAdminUi": true,
    "clientThemeVariant": "",
    "skipClient": false,
    "skipServer": false,
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "pages": [],
    "nativeLanguage": "en",
    "entities": ["BankAccount", "Label", "Operation"]
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity BankAccount {
  name String required
  balance BigDecimal required
}
entity Label {
  label String required minlength(3)
}
entity Operation {
  date Instant required
  description String
  amount BigDecimal required
}
relationship OneToMany {
  BankAccount{operation} to Operation{bankAccount(name)}
}
relationship ManyToOne {
  BankAccount{user(login)} to User
}
relationship ManyToMany {
  Operation{label(label)} to Label{operation}
}

paginate Operation with infinite-scroll

Environment and Tools

openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-24)
OpenJDK 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

git version 2.31.1.windows.1

node: v15.12.0

npm: 7.8.0

Docker version 20.10.5, build 55c4c88

docker-compose version 1.29.0, build 07737305

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)
@atomfrede
Copy link
Member

Can you do a PR? Looks like a bug.

@pascalgrimaud
Copy link
Member

Adding a bounty on this, as it's a bug

@pascalgrimaud pascalgrimaud added $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $100 https://www.jhipster.tech/bug-bounties/ labels May 28, 2021
@sbrunecker
Copy link
Contributor Author

Can you do a PR? Looks like a bug.

Sure, I'll do it over the weekend.

@atomfrede
Copy link
Member

Maybe I have some time this evening.

atomfrede added a commit to atomfrede/generator-jhipster that referenced this issue May 28, 2021
all relevant front files are generated with cache busting so we can cache them in production
for quite a long time.

closes jhipster#15126
atomfrede added a commit to atomfrede/generator-jhipster that referenced this issue May 28, 2021
all relevant front files are generated with cache busting so we can cache them in production
for quite a long time.

closes jhipster#15126
@pascalgrimaud pascalgrimaud added this to the 7.1.0 milestone Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: bug 🐛 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: cache theme: java $100 https://www.jhipster.tech/bug-bounties/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants