Skip to content

[Cache] Doc context aware adapters, aka hierarchical invalidation #6858

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

Closed

Conversation

nicolas-grekas
Copy link
Member

No description provided.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Aug 7, 2016

I'd happily accept any suggestions for making the explanations more detailed. It's hard to write doc when things seem obvious because you wrote the code...

- expiration based invalidation for time related dependencies.

.. versionadded:: 3.2
Tags and namespace based invalidation were introduced in Symfony 3.2.
Copy link
Member

Choose a reason for hiding this comment

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

I believe it should be "was" here, as it's refering to "X based invalidation", which is singular.

invalidation version number (conceptually similar to their latest invalidation
date). When only one adapter is used, items and tags are all stored in the same
place. By using two adapters, you can e.g. store some big cached items on the
filesystem or in the database, and keep tags in a Redis database to sync all your
Copy link
Member

Choose a reason for hiding this comment

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

please remove the serial comma before "and keep"

@wouterj
Copy link
Member

wouterj commented Aug 7, 2016

Sorry, was distracted for some time during the review of this PR. I've now finished reviewing this article, thanks for documenting this feature!

status: needs work

@Koc
Copy link
Contributor

Koc commented Aug 7, 2016

How to configure tag aware cache using framework config?

@nicolas-grekas
Copy link
Member Author

@Koc I don't know yet :) would need a PR on FrameworkBundle.

nicolas-grekas added a commit to symfony/symfony that referenced this pull request Aug 7, 2016
…TagAwareRedisAdapter) (nicolas-grekas)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Cache] Add generic TagAwareAdapter wrapper (replaces TagAwareRedisAdapter)

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

This PR replaces TagAwareRedisAdapter introduced in #19047 by a generic `TagAwareAdapter` that works with any two adapters.

Commits
-------

288308b [Cache] Add generic TagAwareAdapter wrapper (replaces TagAwareRedisAdapter)
@nicolas-grekas nicolas-grekas force-pushed the cache-invalidation branch 2 times, most recently from d30112d to f753506 Compare August 8, 2016 19:22
// or invalidate all items related to `tag_1` or `tag_3`
$cache->invalidateTags(array('tag_1', 'tag_3'));

Of course when you know the cache key, it's better to call
Copy link
Contributor

@mickaelandrieu mickaelandrieu Aug 9, 2016

Choose a reason for hiding this comment

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

I would reword that this way:

Using Cache tags invalidation is very useful when you don't need to know the cache key to delete.

And I will mention $cache->deleteItem('cache_key'); in the previous example (self-explained).

WDYT ?

@mickaelandrieu
Copy link
Contributor

The docs is clear to me (non-native english).

Big thanks to you @nicolas-grekas ! I want to play with this component now ^^

The Symfony Cache component provides three mechanisms to help solve this problem:

* Tags based invalidation for managing data dependencies;
* Namespace based invalidation for context dependend data;
Copy link
Contributor

Choose a reason for hiding this comment

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

dependent

@nicolas-grekas
Copy link
Member Author

Comments addressed, examples updated. More comments welcomed :)

``Vary: User-Agent`` or ``Vary: Accept-Encoding`` HTTP headers::

$perUserAgentCache = $httpCache->fork($varyingUserAgent);
$perAcceptEndoginPerUserAgentCache = $childCache->fork($varyingAcceptEncoding);
Copy link
Contributor

Choose a reason for hiding this comment

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

Encoding

fabpot added a commit to symfony/symfony that referenced this pull request Aug 19, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Cache] Add PDO + Doctrine DBAL adapter

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

This PR adds a PDO adapter for our PSR-6 cache items. The implementation heavily borrows from PdoSessionHandler.

Commits
-------

82a0de2 [Cache] Add PDO + Doctrine DBAL adapter
symfony-splitter pushed a commit to symfony/cache that referenced this pull request Aug 19, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Cache] Add PDO + Doctrine DBAL adapter

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

This PR adds a PDO adapter for our PSR-6 cache items. The implementation heavily borrows from PdoSessionHandler.

Commits
-------

82a0de2 [Cache] Add PDO + Doctrine DBAL adapter
@kbond
Copy link
Member

kbond commented Aug 25, 2016

Maybe it is just me but I am not quite understanding the "Namespaces"/"Forkable" feature. Perhaps a more extensive example?

@nicolas-grekas
Copy link
Member Author

@kbond see https://www.drupal.org/developing/api/8/cache/contexts for another use case of this feat. Maybe one should first read this page then help me find the right words to explain the feat. ? :)
This is hierarchical invalidation done from the outside, (the inside being prefixing keys explicitly e.g. ->getItem('foo/bar'))

@nicolas-grekas nicolas-grekas changed the title [Cache] Add chapter about invalidation, tags, etc. [Cache] Doc forkable adapters, aka namespace based invalidation Sep 2, 2016
* Expiration based invalidation for time related dependencies.

.. versionadded:: 3.2
Tags and namespace based invalidation was introduced in Symfony 3.2.
Copy link
Member

Choose a reason for hiding this comment

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

were introduced

@nicolas-grekas
Copy link
Member Author

I just rewrote entirely this paragraph, any better?

@Koc
Copy link
Contributor

Koc commented Sep 16, 2016

Much better now for me

@nicolas-grekas nicolas-grekas changed the title [Cache] Doc forkable adapters, aka namespace based invalidation [Cache] Doc context aware adapters, aka hierarchical invalidation Sep 16, 2016
@kbond
Copy link
Member

kbond commented Sep 16, 2016

I'm understanding it much better as well. The example is great!

@nicolas-grekas
Copy link
Member Author

Closing, see symfony/symfony#19521 (comment)

@nicolas-grekas nicolas-grekas deleted the cache-invalidation branch September 23, 2016 18:51
wouterj added a commit that referenced this pull request Oct 20, 2016
…olas-grekas)

This PR was merged into the master branch.

Discussion
----------

[Cache] Add chapter about invalidation, tags, etc.

This is a subpart of #6858 that tells only about merged features. Please merge asap so we can rebase #6858 on top and focus on its specific bits afterwards :)

Commits
-------

0ffc261 [Cache] Add chapter about invalidation, tags, etc.
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.

10 participants