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

Corrected caching docs and deprecation behaviour (fixes #8272) #8274

Conversation

chillu
Copy link
Member

@chillu chillu commented Jul 19, 2018

See #8272 for context

The HTTP.cache_control behaviour was removed in https://github.com/silverstripe/silverstripe-framework/pull/8166/files#diff-523aa2e152e10c465a85790ac13e30e4L402,
but not properly deprecated - it just silently stopped working.

This was a different approach to HTTP.vary deprecation, which I think why it's an omission (@dhensby couldn't remember).

@@ -184,32 +184,22 @@ class PageController extends ContentController
}
```

## Defaults
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't believe we still had this in there, it's completely out of date :(

@chillu
Copy link
Member Author

chillu commented Jul 19, 2018

@dhensby and @sminnee saw a WIP diff of the proposed changes around the $maxAge param, and agreed with the direction. The remaining commits in this PR still require peer review.


$supportedDirectives = ['max-age', 'no-cache', 'no-store', 'must-revalidate'];
if ($foundUnsupported = array_diff(array_keys($configCacheControl), $supportedDirectives)) {
throw new \LogicException(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add this to the PHPDoc please?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

public function testDeprecatedVaryHandling()
{
/** @var Config */
Config::inst()->update(
Copy link
Contributor

Choose a reason for hiding this comment

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

- Config::inst()->update(
+ Config::modify()->set(

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh is that what the cool kids are using these day? :D Updated.

Copy link
Contributor

@dhensby dhensby left a comment

Choose a reason for hiding this comment

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

I'll take a look at the tests myself

@@ -68,6 +68,65 @@ public function testSetMaxAge($state, $immutable)
}
}

public function testEnableCacheWithMaxAge()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these tests aren't needed and we should just update the provider and the existing tests...

Copy link
Member Author

Choose a reason for hiding this comment

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

For this particular test (testEnableCacheWithMaxAge), I agree with you - it's already covered by testSetMaxAge.

But otherwise, I find this particular use of PHPUnit providers quite unreadable actually - it took me a while to figure out what the meaning of $immutable is in this context. I think providers are fine when they contain one dimension, since that's something you can keep in your head. But otherwise, DRY principles apply differently to unit tests: In my opinion, clarity (and sometimes verbosity) is more important than brevity. I can understand what testEnableCacheWithMaxAgeAppliesWhenLevelDoesNot tests. I couldn't understand this if it was mixed in as a third array element in provideCacheStates, even when using named data provider sets

Copy link
Member Author

Choose a reason for hiding this comment

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

Update: The difference with testEnableCacheWithMaxAge (compared to testSetMaxAge) is the max-age setting via argument rather than setter. Not all methods in your data provider have this argument, because it doesn't make sense for all of them - so you'd either have to use a different data provider, or add more confusing dimensions to the existing one. And since the assertions change between enableCache and publicCache usage, I don't think a new data provider capturing both cases will be more readable.

@dhensby dhensby dismissed their stale review July 19, 2018 20:45

ok - maybe not :P

@@ -59,8 +59,8 @@ Does not set `private` directive, use `privateCache()` if this is explicitly req
Simple way to set cache control header to a cacheable state.
Use this method over `publicCache()` if you are unsure about caching details.

Removes `no-store` and `no-cache` directives; other directives will remain in place.
Use alongside `setMaxAge()` to indicate caching.
Removes the `no-store` directive; other directives will remain in place.
Copy link
Contributor

Choose a reason for hiding this comment

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

This still isn't quire true; it doesn't remove the no-store directive unless a max-age is supplied.

Copy link
Member Author

Choose a reason for hiding this comment

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

Amended

@chillu chillu force-pushed the pulls/4.2/cache-docs-and-deprecation-handling branch from d92e891 to 5670280 Compare July 22, 2018 23:12
@dhensby dhensby changed the base branch from 4.2 to 4.2.0 July 23, 2018 11:46
@dhensby dhensby changed the base branch from 4.2.0 to 4.2 July 23, 2018 11:48
@dhensby dhensby force-pushed the pulls/4.2/cache-docs-and-deprecation-handling branch from 5670280 to bdab939 Compare July 23, 2018 18:05
@dhensby dhensby changed the base branch from 4.2 to 4.2.0 July 23, 2018 18:06
@dhensby dhensby force-pushed the pulls/4.2/cache-docs-and-deprecation-handling branch from bdab939 to d12c2fe Compare July 23, 2018 18:09
@dhensby dhensby merged commit e1cdc8f into silverstripe:4.2.0 Jul 24, 2018
@dhensby dhensby deleted the pulls/4.2/cache-docs-and-deprecation-handling branch July 24, 2018 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants