8000 [Contracts] Add Cache contract to extend PSR-6 with tag invalidation, callback-based computation and stampede protection by nicolas-grekas · Pull Request #28096 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Contracts] Add Cache contract to extend PSR-6 with tag invalidation, callback-based computation and stampede protection #28096

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
Sep 4, 2018

Conversation

nicolas-grekas
Copy link
Member
@nicolas-grekas nicolas-grekas commented Aug 1, 2018
Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Let's separate the useful interfaces of the Cache component in Contracts.
This does not include PruneableInterface, MarshallerInterface nor *AdapterInterface because they are too specific to the component.

But CacheInterface, TawAwareCacheInterface and ItemInterface form a nice consistent set of features on top of PSR-6.

Updating the Cache component to use these interfaces will be done in a separate PR so that we can focus on the contract itself here.

@nicolas-grekas nicolas-grekas added this to the next milestone Aug 1, 2018
@nicolas-grekas nicolas-grekas force-pushed the contract-cache branch 3 times, most recently from b5b7e79 to 9c19606 Compare August 8, 2018 07:45
@nicolas-grekas
Copy link
Member Author

Now with a GetForCacheItemPoolTrait to help implementing the CacheInterface::get() method in PSR-6 implementations.

@nicolas-grekas
Copy link
Member Author

Also with ExtendedCacheInterface + ExtendedTagAwareCacheInterface for pools implementing both intrefaces: the proposed ones + PSR-6's CacheItemPoolInterface.

use Psr\Cache\CacheItemPoolInterface;

/**
* An interface that extends TawAwareCacheInterface with the methods from PSR-6's CacheItemPoolInterface.
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a typo: Taw => Tag, also present in the PR description.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed thanks

*
* When implemented on a PSR-6 pool, invalidation should not apply
* to deferred items. Instead, they should be committed as usual.
* This allows replacing old tagged values by news ones without
Copy link
Member

Choose a reason for hiding this comment

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

new ones

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, thanks

Copy link
Member
@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Great.
I had a discussion with @nicolas-grekas.
Approved with changes

/**
* An interface that extends TagAwareCacheInterface with the methods from PSR-6's CacheItemPoolInterface.
*/
interface ExtendedTagAwareCacheInterface extends TagAwareCacheInterface, CacheItemPoolInterface
Copy link
Member

Choose a reason for hiding this comment

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

As discussed: Remove this.

/**
* An interface that extends CacheInterface with the methods from PSR-6's CacheItemPoolInterface.
*/
interface ExtendedCacheInterface extends CacheInterface, CacheItemPoolInterface
Copy link
Member

Choose a reason for hiding this comment

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

We should remove this.

@nicolas-grekas
Copy link
Member Author

Thanks @Nyholm , PR updated.

@Nyholm
Copy link
Member
Nyholm commented Aug 30, 2018

Thank you. Im 👍

@nicolas-grekas nicolas-grekas force-pushed the contract-cache branch 5 times, most recently from 09b706b to f7cad20 Compare September 4, 2018 06:46
@nicolas-grekas
Copy link
Member Author

(rebased)

@nicolas-grekas
Copy link
Member Author

Addressed, thanks.

… callback-based computation and stampede protection
interface CacheInterface
{
/**
* @param callable(ItemInterface):mixed $callback Should return the computed value for the given key/item
Copy link
Member Author

Choose a reason for hiding this comment

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

that's the declaration for the return type of the callable

interface CacheInterface
{
/**
* @param callable(ItemInterface):mixed $callback Should return the computed value for the given key/item
Copy link
Member Author

Choose a reason for hiding this comment

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

that's the declaration for the return type of the callable

@fabpot
Copy link
Member
fabpot commented Sep 4, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit ca6478b into symfony:master Sep 4, 2018
fabpot added a commit that referenced this pull request Sep 4, 2018
…g invalidation, callback-based computation and stampede protection (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Contracts] Add Cache contract to extend PSR-6 with tag invalidation, callback-based computation and stampede protection

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

Let's separate the useful interfaces of the Cache component in Contracts.
This does not include `PruneableInterface`, `MarshallerInterface` nor `*AdapterInterface` because they are too specific to the component.

But `CacheInterface`, `TawAwareCacheInterface` and `ItemInterface` form a nice consistent set of features on top of PSR-6.

Updating the Cache component to use these interfaces will be done in a separate PR so that we can focus on the contract itself here.

Commits
-------

ca6478b [Contracts] Add Cache contract to extend PSR-6 with tag invalidation, callback-based computation and stampede protection
@nicolas-grekas nicolas-grekas deleted the contract-cache branch September 4, 2018 07:23
nicolas-grekas added a commit that referenced this pull request Sep 4, 2018
This PR was merged into the 4.2-dev branch.

Discussion
----------

[Cache] leverage Contracts\Cache

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

Implementing #28096

Commits
-------

0a1220f [Cache] leverage Contracts\Cache
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
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
0