Skip to content
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

[FrameworkBundle] Added a keep-in-memory option for cache adapters #30984

Closed
wants to merge 1 commit into from

Conversation

pborreli
Copy link
Contributor

@pborreli pborreli commented Apr 7, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no (option is false by default)
Deprecations? no
Tests pass? need tests
Fixed tickets N/A
License MIT
Doc PR symfony/symfony-docs#...

Adding a keep-in-memory option for cache adapters which is basically a shortcut using ChainAdapter with ArrayCache as first adapter.

@pborreli
Copy link
Contributor Author

pborreli commented Apr 7, 2019

@nicolas-grekas fixed your feedbacks, thanks

@@ -995,6 +995,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
->info('Overwrite the setting from the default provider for this adapter.')
->end()
->scalarNode('clearer')->end()
->booleanNode('keep_in_memory')->defaultFalse()->end()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add an info() tag?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

this is missing an update in the corresponding xsd
don't forget opening a doc PR please
also, naming: keep-in-memory? enable-local-cache? any better idea?

}

unset($tags[0]['keep_in_memory']);

if (!empty($tags[0])) {
throw new InvalidArgumentException(sprintf('Invalid "%s" tag for service "%s": accepted attributes are "clearer", "provider", "name", "namespace", "default_lifetime" and "reset", found "%s".', $this->cachePoolTag, $id, implode('", "', array_keys($tags[0]))));
Copy link
Member

Choose a reason for hiding this comment

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

the new attribute should be listed here

@nicolas-grekas nicolas-grekas changed the title [WIP] Added a keep-in-memory option for cache adapters [FrameworkBundle] Added a keep-in-memory option for cache adapters Apr 8, 2019
@dunglas
Copy link
Member

dunglas commented Apr 8, 2019

Shouldn’t this feature be enabled by default, with an option to opt out?

@nicolas-grekas
Copy link
Member

Shouldn’t this feature be enabled by default, with an option to opt out?

chaining can introduce subtle desynchronization effects because the upper pools don't know when the items in lower pools are invalidated. That's true for the remaining expiration time but also for tag-based invalidation.

An idea could be to default to using a 1s local cache when tags are not used.

This makes me think we should forbid using tags+keep-in-memory together, and that we should make keep-in-memory an integer, that would default to 1, which would set the number of seconds the local pool keeps items when the real expiration date is unknown.

@Tobion
Copy link
Member

Tobion commented May 9, 2019

What if the cache pool is already using the ArrayAdapter? Then enabling the option does not make sense and should probably throw an error.

@Nyholm
Copy link
Member

Nyholm commented Jun 24, 2019

Thank you for this PR.

This PR is just a shortcut for creating an ChainAdapter. I agree that it is super tricky to understand how to actually create a ChainAdapter. I just submitted a PR to the docs to fix the broken example. (That I created a few months ago...)

I fear that this PR will only make configuration more complex and harder to understand. I vote 👎 because I think we should promote "the proper way" instead of adding shortcuts.

@nicolas-grekas
Copy link
Member

Closing in favor of #32294, thank you @pborreli!

fabpot added a commit that referenced this pull request Jul 5, 2019
…y providing several adapters (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[FrameworkBundle] Allow creating chained cache pools by providing several adapters

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

Replaces #30984, follows symfony/symfony-docs#11813

This PR allows defining several adapters for one pool. When doing so, this defines a chain pool.
The benefit is that all chained pools get automatic namespace and lifetime, so things are transparent:

```yaml
pools:
    my_chained_pool:
        default_lifetime: 12
        adapters:
          - cache.adapter.array
          - cache.adapter.filesystem
          - {name: cache.adapter.redis, provider: 'redis://foo'}
```

(see fixtures for example of PHP/XML config)

/cc @Nyholm @pborreli FYI

Commits
-------

29ba091 [FrameworkBundle] Allow creating chained cache pools by providing several adapters
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
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.

7 participants