-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Implement PSR-16 SimpleCache #20636
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
Conversation
I'm kinda confused here, I don't know the cache component in depth but it looks like you implemented CounterInterface in the adapters, but then to actually use the new CacheInterface you have to use the simple cache adapter on top of the PSR-6 cache pool, therefore losing the natively implemented CounterInterface?! Maybe you're just not finished yet :) |
Ah no I missed this..
All is well :) |
40ea9fd
to
47f44a8
Compare
Questions sent to the FIG: On CounterInterface:
On CacheInterface:
|
Thanks you @nicolas-grekas for creating this PR. Saved me some time :-) |
} | ||
} | ||
|
||
$e = $this->doSave(array($id => $step), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this implementation in the base adapter is suspicious. The spec asks for atomicity, but atomicity requires to overwrite this method in each child adapter. An adapter not overwriting it would not provide atomicity, thus breaking the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #20636 (comment)
public function getMultiple($keys) | ||
{ | ||
foreach ($this->pool->getItems($keys) as $key => $item) { | ||
yield $key => $item->get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec says @return array
, which excludes generators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on purpose @Seldaek?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really on purpose. Please email on fig ML to keep everything centralized there because otherwise stuff will get lost.. Not sure if I like generators here though, if you get multiple keys you most likely want to have them in an array where you access every result by key, and not have to loop over it.. But it's also kinda easy to wrap iterator_to_array so not huge deal either way.
*/ | ||
public function getMultiple($keys) | ||
{ | ||
foreach ($this->pool->getItems($keys) as $key => $item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this call would be done only when starting to iterate the generator, which is too late
if (is_numeric($value = $item->get())) { | ||
$step += $value; | ||
} | ||
$item->set($step); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fallback logic does not respect the spec, as it is not atomic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Seldaek shouldn't the spec use a normative MUST or SHOULD on this topic? (SHOULD would be my pref so that fallback implems are kind of OK, it'd then be up to the user to chose an implem+backend that provides real atomicity when required).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is only the phpdoc here in the spec, and it says Increment atomically
so it looks like a MUST for now (at least I understand it this way when reading it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah people complained about it being part of the CacheInterface initially because it wasn't possible to guarantee it can be implemented atomically.. So we split it, to keep it MUST, because otherwise it's kinda useless really IMO. I think it's still fine for implementors to provide non-atomic if they want, but at least violating the spec means you should warn people and make them aware that non-atomic ones are a bad idea if you do anything related to security or just overall don't want to lose data in high-concurrency settings.
New unresolved issues with PSR-16 draft:
|
47f44a8
to
858d93b
Compare
if (is_numeric($result = $this->doIncrement($id, (int) $step))) { | ||
return $result; | ||
} | ||
CacheItem::log($this->logger, 'Failed to increment key "{key}"', array('key' => $key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you call this code also from decrement, this message may be misleading in some cases
This PR achieved its goal to spot edge cases in PSR-16. |
…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
Let's review PSR-16 by looking at a possible actual implementation of it, helping @Seldaek in his quest to pass it to the FIG.
See also: