Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache] Allow and use generators in AbstractAdapter #17438

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 1 commit into from
Jan 25, 2016

Conversation

nicolas-grekas
Copy link
Member

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

The most important enhancement is allowing doFetch to return a generator, which wasn't possible before.
The other changes add strictness.

@nicolas-grekas nicolas-grekas changed the title [Cache] Use generators [Cache] Allow and use generators in AbstractAdapter Jan 19, 2016
* @return bool True if the pool was successfully cleared, false otherwise.
*/
abstract protected function doClear();
abstract protected function doClear($namespace);
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 propose adding $namespace to this abstract method so that adapters can flush only a subpart of their global pool if that applies

@@ -114,7 +116,7 @@ public function getItem($key)
$this->commit();
}
if (isset($this->deferred[$key])) {
return $this->deferred[$key];
return clone $this->deferred[$key];
Copy link
Member Author

Choose a reason for hiding this comment

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

bug fix

@nicolas-grekas nicolas-grekas force-pushed the cache branch 2 times, most recently from 2bc3bfa to 5b429cf Compare January 19, 2016 14:27
/**
* @internal
*/
const CAST_PREFIX = "\0Symfony\Component\Cache\CacheItem\0";
Copy link
Member Author

Choose a reason for hiding this comment

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

ping @dunglas

Copy link
Member

Choose a reason for hiding this comment

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

👍

@stof
Copy link
Member

stof commented Jan 19, 2016

@nicolas-grekas is this subject to race conditions between reading items and updating the cache during the iteration ?

@nicolas-grekas
Copy link
Member Author

@stof I'd say it's up to the concrete adapter to deal with this. If one adapter chooses to return an iterator/generator, it's up to it to deal with this kind of consequences. Would you agree?

@stof
Copy link
Member

stof commented Jan 19, 2016

@nicolas-grekas even if they don't return a generator, the cache system still use one, and performs doFetch in the middle of the generator iteration. So it may also be impacted.

@nicolas-grekas
Copy link
Member Author

If they do return an array (like Apcu/Doctrine adapters) then the result set is "frozen" in the generator. The behavior is well defined, so not subject to race conditions. PSR-6 doesn't specify if returned traversable are "live" or not, but we could argue that the "array" requirement means they should be frozen. We maybe should add this in our test suite, don't you think?

@stof
Copy link
Member

stof commented Jan 19, 2016

@nicolas-grekas adding this to the testsuite is a good idea (and is what I suggested in php-cache/integration-tests#34 (comment))

Are you sure that adapters cannot be affected ? doFetch is not at the beginning of the iteration

@nicolas-grekas
Copy link
Member Author

@stof I moved the doFetch first and also added an isset check around deferred.
About deferred, this should be always empty since we commit them before fetching.
$deferred can still be non empty if saving some deferred failed.
Could you review the failure handling logic around deferred? It's a complex topic and you may have some ideas for the better.

@nicolas-grekas
Copy link
Member Author

@stof btw adding the test we're talking about should maybe not be included in the integration tests but only in our own test suite, since psr-6 has no requirements here (unless someone explains that there are?)

@nicolas-grekas nicolas-grekas force-pushed the cache branch 2 times, most recently from 2fb6243 to 5cd0317 Compare January 19, 2016 21:26
@@ -76,7 +76,7 @@
"symfony/yaml": "self.version"
},
"require-dev": {
"cache/integration-tests": "^0.6",
"cache/integration-tests": "dev-master",
Copy link
Member Author

Choose a reason for hiding this comment

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

We need this until the test suite fits our needs. I suggest we add a version number when the Component is stable enough/feature full, in a few weeks.

Copy link
Member

Choose a reason for hiding this comment

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

This could be changed to "^0.7" now, I guess?

$ok = false;

foreach ($v as $key => $value) {
@trigger_error(sprintf('Failed to cache key "%s" of type "%s"', is_object($value) ? get_class($value) : gettype($value)));
Copy link
Member Author

Choose a reason for hiding this comment

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

This could help someone someday figure out what's wrong...

@nicolas-grekas
Copy link
Member Author

@stof PR is ready. Please note that I'm now AFK until the end of January, so feel free to take over this PR as I won't be able to resolve any comments until then.

@nicolas-grekas nicolas-grekas force-pushed the cache branch 2 times, most recently from 955079e to 4d8b6f9 Compare January 20, 2016 08:28
@nicolas-grekas
Copy link
Member Author

No comment? Ping @symfony/deciders

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 0ba851a into symfony:master Jan 25, 2016
fabpot added a commit that referenced this pull request Jan 25, 2016
…icolas-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Cache] Allow and use generators in AbstractAdapter

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The most important enhancement is allowing doFetch to return a generator, which wasn't possible before.
The other changes add strictness.

Commits
-------

0ba851a [Cache] Allow and use generators in AbstractAdapter
@nicolas-grekas nicolas-grekas deleted the cache branch January 25, 2016 12:24
@fabpot fabpot mentioned this pull request May 13, 2016
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