Skip to content

[Cache] Implement PSR-16 SimpleCache v1.0 #20694

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

Merged
merged 3 commits into from
Jan 23, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 30, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? not yet
Fixed tickets -
License MIT
Doc PR symfony/symfony-docs#7409

Second iteration on the topic after #20636 raised some issues.

Please don't squash while merging.

parent::__construct($namespace, $defaultLifetime);

$this->pool = $pool;
$this->miss = new stdClass();
Copy link
Member

Choose a reason for hiding this comment

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

missing \ here

*/
protected function doFetch(array $ids)
{
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
Copy link
Member

Choose a reason for hiding this comment

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

this call would be performed only when the iteration starts rather than when doFetch is called. Is it an issue ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The ids have already been validated by the AbstractAdapter. Since this is the only situation that is allowed to throw, it's OK this way to me.

} catch (SimpleCacheException $e) {
throw $e;
} catch (Psr6CacheException $e) {
throw new InvalidArgumentException($e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

I would link the original exception as previous exception, to keep the original stack trace (same everywhere of course)

@stof
Copy link
Member

stof commented Nov 30, 2016

@Seldaek @nicolas-grekas @dragoonis @Nyholm it may be worth starting the work on a shared testsuite for simple-cache too (similar to the one existing for PSR-6)

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@nicolas-grekas nicolas-grekas force-pushed the simple-cache branch 3 times, most recently from acd7065 to 72ba3a3 Compare December 9, 2016 10:20
@nicolas-grekas
Copy link
Member Author

Status: needs review
PR updated to fit simple-cache v0.3. The PSR-6 to PSR-16 is now called Symfony\Component\Cache\Simple\Psr6Cache, which opens a new namespace to provide native e.g. Simple\ApcuCache implementations. WDYT?
The PSR-16 to PSR-6 bridge is named Symfony\Component\Cache\Adapter\SimpleCacheAdapter (following existing convention).
Code is tested by the PSR-6 test suite, with both bridges wired together.
This means coverage is full for SimpleCacheAdapter and partial for Psr6Cache, until we work on a shared PSR-16 test suite with @Nyholm.

I'd propose to merge this PR without waiting for more tests nor for more progress from the fig. This would unlock some other things I'd like to do on top of this one, but deserve another PR.
If the fig does not deliver on time for 3.3, then it will still be easy to revert before tagging.

} catch (SimpleCacheException $e) {
throw $e;
} catch (Psr6CacheException $e) {
throw new InvalidArgumentException($e->getMessage());
Copy link
Member Author

Choose a reason for hiding this comment

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

here (and similar below), I think we don't need to add $e as a "previous" to the thrown exception: by PSR-6, there can be only one reason for the $e exception: invalid key. Having the previous throwing site (file, line, stack) is not going to help: the error is the $key, so the message is the only thing that is useful IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

there could be a second reason: misbehaving cache implementation. In this case, knowing the original location of the exception could help understand whether the issue is in the key, or in the key validation. And btw, it would still point people to the code implementing the key validation, showing them the logic used to validate it.
So IMO, it is still a good idea to link the original exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, added

{
protected $skippedTests = array(
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
Copy link
Member

Choose a reason for hiding this comment

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

should we run a second set of tests for the SimpleCacheAdapter by making it use a shared cache internally ?

Copy link
Member Author

Choose a reason for hiding this comment

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

ArrayAdapter replaced by FilesystemAdapter

} catch (SimpleCacheException $e) {
throw $e;
} catch (Psr6CacheException $e) {
throw new InvalidArgumentException($e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

there could be a second reason: misbehaving cache implementation. In this case, knowing the original location of the exception could help understand whether the issue is in the key, or in the key validation. And btw, it would still point people to the code implementing the key validation, showing them the logic used to validate it.
So IMO, it is still a good idea to link the original exception.

@stof
Copy link
Member

stof commented Jan 3, 2017

@Nyholm @nicolas-grekas have you made any progress on the shared PSR-16 testsuite ?

@Nyholm
Copy link
Member

Nyholm commented Jan 3, 2017

Yes. I do. Expect it to be done at the very latest this weekend.

@dragoonis
Copy link

dragoonis commented Jan 3, 2017 via email

@Nyholm
Copy link
Member

Nyholm commented Jan 4, 2017

Test PR is here: php-cache/integration-tests#66

@nicolas-grekas nicolas-grekas changed the title [Cache] Implement PSR-16 SimpleCache v0.3 [Cache] Implement PSR-16 SimpleCache v1.0 Jan 4, 2017
@nicolas-grekas
Copy link
Member Author

php-cache/integration-tests v0.14.0 integrated, tests green.
PR is ready
some tests could be enhanced, but this should not be a blocker

@nicolas-grekas nicolas-grekas force-pushed the simple-cache branch 4 times, most recently from 1ae92f6 to f1a6827 Compare January 6, 2017 11:09
@nicolas-grekas
Copy link
Member Author

Status: needs review
test suite fixed and updated, all green

@nicolas-grekas nicolas-grekas force-pushed the simple-cache branch 4 times, most recently from e527505 to 2b5cc7f Compare January 8, 2017 22:27
@nicolas-grekas nicolas-grekas force-pushed the simple-cache branch 3 times, most recently from 781b9d2 to 0ab20ae Compare January 15, 2017 17:01
@fabpot
Copy link
Member

fabpot commented Jan 23, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 6219dd6 into symfony:master Jan 23, 2017
fabpot added a commit that referenced this pull request Jan 23, 2017
…kas)

This PR was squashed before being merged into the 3.3-dev branch (closes #20694).

Discussion
----------

[Cache] Implement PSR-16 SimpleCache v1.0

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | not yet
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#7409

Second iteration on the topic after #20636 raised some issues.

Please don't squash while merging.

Commits
-------

6219dd6 [Cache] Create PSR-16 variants of all PSR-6 adapters
99ae9d6 [Cache] Move adapter implementations to traits
848a33e [Cache] Implement PSR-16 SimpleCache v1.0
@nicolas-grekas nicolas-grekas deleted the simple-cache branch January 23, 2017 21:18
@dragoonis
Copy link

👍 🥇

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.

6 participants