Skip to content

[Cache] Add nonce based cache invalidation to ApcuAdapter #18716

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
May 12, 2016

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented May 5, 2016

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

APCu cache invalidation is tedious because it can't be done from the cli.
This PR adds and wires a nonce based cache invalidation strategy to work around this limitation.

}
}
foreach ($values as $id => $v) {
$values[$id] = unserialize(substr($v, $this->nonceLen));
Copy link
Member

Choose a reason for hiding this comment

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

Why not moving this to the loop above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question: because unserialization involves userland code, which means can be slow. But IMHO we need to invalidate fast.

@xabbuh
Copy link
Member

xabbuh commented May 6, 2016

Having the nonce as a container parameter makes the APCu cache barely unusable in the dev environment where the container may be rebuilt quite often, doesn't it?

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented May 6, 2016

Except that our system caches (serializer & validation for now) are not enabled in debug mode.
Also, caches are registered with a clearer which means they are already cleared quite often in dev.

@nicolas-grekas
Copy link
Member Author

I simplified the implementation to the very minimum so that no overhead is added anymore to each apcu_fetch/store. I also replaced the container parameter by an inline value for the nonce.

It has the drawback that @xabbuh outlined: the cache in dev is going to be cleared more often than strictly required. Yet I think this does not matter compared to the main benefit (we even already disable most caches in dev):

As you know, there is currently no way to invalidate an FPM/Apache apcu cache from the CLI, other than restarting FPM/Apache on deployment. Even if it's a best practice, not everyone is able to do it.
Nonce-based invalidation fixes this. Thus, it makes apcu usable again in prod for everyone, by default.

@dunglas
Copy link
Member

dunglas commented May 10, 2016

👍

@nicolas-grekas
Copy link
Member Author

ping @symfony/deciders votes pendind for 3.1-beta which should/may be released tomorrow

@fabpot
Copy link
Member

fabpot commented May 12, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit a7899fe into symfony:master May 12, 2016
fabpot added a commit that referenced this pull request May 12, 2016
…ter (nicolas-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Cache] Add nonce based cache invalidation to ApcuAdapter

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

APCu cache invalidation is tedious because it can't be done from the cli.
This PR adds and wires a nonce based cache invalidation strategy to work around this limitation.

Commits
-------

a7899fe [Cache] Add nonce based cache invalidation to ApcuAdapter
@nicolas-grekas nicolas-grekas deleted the cache-salt branch May 12, 2016 20:52
@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