Skip to content

Conversation

@tinexw
Copy link
Contributor

@tinexw tinexw commented Oct 4, 2017

First attempt at providing a solution for #9432

Note that the properties for public and private are currently called cache-public and cache-private. I'm not sure if it's possible to change that? I can look into it if the overall approach is ok.

Assert.state(this.cachePeriod == null || this.cacheControl == null,
"Only one of cache-period or cache-control may be set.");
if (this.cacheControl != null) {
if (this.cacheControl.getMaxAge() != null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cacheControl has been asserted above, what is the need to check that is not null again?

Copy link
Contributor Author

@tinexw tinexw Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's asserted that not both cachePeriod and cacheControl are set. So cacheControl can be null at this point.

}

static org.springframework.http.CacheControl createCacheControl(CacheControl cacheControlProperties) {
org.springframework.http.CacheControl cacheControl;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • it looks weird for me, it creates the instance of org.springframework.http.CacheControl by updating a property (as maxAge), without any kind of builder or instantiating the constructor.

  • Also "createCacheControl" inside a class named "CacheControl" to return an object from another different class...what about "transformToHttpSpringCacheControl"

  • the method might be an instance method of CacheControl, so you don't need to pass the argument and cacheControlProperties call the method getting the new type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks weird for me [...]

Yes, it looks weird to me too... But the org.springframework.http.CacheControldoesn't have a public constructor or any setters. It it itself more like a builder (all methods return the instance) that builds a string (the cache header).

Also "createCacheControl" inside a class named "CacheControl" [...]

Done and I also renamed the CacheControl class to CacheControlProperties

the method might be an instance method

Changed

cacheControlProperties.getsMaxAge(),
TimeUnit.SECONDS);
}
return cacheControl;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In mi opinion, this is a very long method, with some if-else, what make easy to loose the track. Might it be separated in meaningful methods what make the method more readable? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extracted some parts but not sure if it really is better know.

@Test
public void cachePeriod() throws Exception {
this.contextRunner.withPropertyValues("spring.resources.cache-period:5")
.run((context) -> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might extract the functionality in a method, such as assertCachePeriod(Context context). There are many nested blocks, uneasy to read. what do you reckon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.contextRunner
.withPropertyValues("spring.resources.cache-control.max-age:5",
"spring.resources.cache-control.proxy-revalidate:true")
.run((context) -> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has the same problem than further up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tinexw tinexw force-pushed the 9432 branch 5 times, most recently from aad2732 to 3507bbf Compare October 12, 2017 18:54
@bclozel bclozel added priority: normal type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 3, 2017
@bclozel bclozel added this to the 2.0.0.RC1 milestone Nov 3, 2017
@tinexw
Copy link
Contributor Author

tinexw commented Nov 14, 2017

@bclozel I addressed your comments, could you have another look, please?

@bclozel
Copy link
Member

bclozel commented Nov 14, 2017

@tinexw I'll definitely polish (if needed) and merge this - it's scheduled for the next milestone. For the record, @fmcejudo is a contributor, just like you.

Thanks for your contribution, really appreciated!

@tinexw
Copy link
Contributor Author

tinexw commented Nov 15, 2017

@bclozel Sorry, I didn't realize it wasn't you. @fmcejudo I addressed your comments, could you have another look, please?

@bclozel
Copy link
Member

bclozel commented Nov 20, 2017

Hi @tinexw - I've merged your changes in e2bc90b and polished things a bit on top. Nothing major, just stuff that happened recently:

  • I've changed my mind about spring.resources.cache-period and spring.resources.cache-control excluding each other; Spring MVC is using CacheControl if both are set, so I chose to mirror that behaviour.
  • Since Use Duration for configuration properties #11080, we now use the Duration type for such configuration keys.

Thanks again for this new contribution!

@bclozel bclozel closed this Nov 20, 2017
@tinexw
Copy link
Contributor Author

tinexw commented Nov 20, 2017

@bclozel Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants