Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] PSR-6 HttpCache store#42295

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Toflar wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromToflar:feature/http-cache-psr6

Conversation

Toflar
Copy link
Contributor

QA
Branch?5.4
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

As per@nicolas-grekas' request, here's a PR to merge myalternative PSR-6 HttpCache store into Symfony itself.
This is a simple copy & paste with a few namespace and test adjustments to get the discussion started for now.

Here are some additional thoughts:

Issues with the currentStoreInterface /HttpCache

  • Does not support auto pruning which means it grows forever. This is has become an even bigger issue since the introduction of theCachingHttpClient which also leverages theHttpCache. So you also grow endlessly big cache directories for your external HTTP requests with Symfony's HttpClient.

  • Does not support cache tagging which is an extremely useful feature for reverse proxies.

  • Does some custom lock handling instead of relying on Symfony's Lock component.

  • Does not support cachingBinaryFileResponses.

Issues with this PR, things to be clarified

  • It's not a 100% the same as my current implementation. Specifically, the currentStoreInterface lacks the methods for the following three capabilities:

    • clear() to be able to flush a cache completely.
    • invalidateTags() to be able to invalidate certain cache items of a given set of cache tags only.
    • prune() to be able to prune expired cache items.
  • If you look at the things thePsr6Store has to do, it kind of becomes evident, thatHttpCache currently delegates too many responsibilities to theStoreInterface.Vary handling and cache key generation e.g. should be the same for all stores.

  • The currentCachingHttpClient relies onHttpCache as well and does not support greedy caching which is something that should be supported too, imho.

  • I think, we should rather replace the currentHttpCache with an alternative and deprecate the current one together with the currentStoreInterface. Imho that alternative could rely on the Symfony Cache abstraction directly. However, we should see if we can add the missing three capabilities to the Cache contracts as they are vital for a reverse proxy cache. We already haveTagAwareCacheInterface forinvalidateTags() but we're lackingprune() andclear() which would both make sense imho.

List of things to do:

  • Update changelog
  • Docs

@carsonbotcarsonbot changed the titlePSR-6 HttpCache store[HttpKernel] PSR-6 HttpCache storeJul 27, 2021
@derrabusderrabus added this to the5.4 milestoneJul 27, 2021
Copy link
Contributor

@OskarStarkOskarStark left a comment

Choose a reason for hiding this comment

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

I left some comments, great work, thank you!

private $locks = [];

/**
* When creating a Psr6Store you can configure a number options.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* When creating a Psr6Store you can configure a number options.
* When creating a Psr6Store you can configure a numberofoptions.


/**
* When creating a Psr6Store you can configure a number options.
* See the README for a list of all available options and their description.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather remove this sentence and add the options to the Symfony docs

}

/**
* Invalidates all cache entries that match the request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes you writeRequest, sometimesrequest, only one should be used

/**
* Releases the lock for the given Request.
*
* @param Request $request A Request instance
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure we need this@param annotation 🤔

$response->headers->set('X-Content-Digest', $contentDigest);

// Make sure the content-length header is present
if (!$response->headers->has('Transfer-Encoding')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it already has aContent-Length header? Do we always override it?

* @param int $expiresAfter
* @param array $tags
*/
private function saveDeferred(CacheItemInterface $item, $data, $expiresAfter = null, $tags = []): bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
privatefunction saveDeferred(CacheItemInterface$item,$data,$expiresAfter =null,$tags = []):bool
privatefunction saveDeferred(CacheItemInterface$item,$data,int$expiresAfter =null,array$tags = []):bool

and remove the doc block?

use Symfony\Component\Lock\LockInterface;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;

class Psr6StoreTest extends TestCase
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class Psr6StoreTestextends TestCase
finalclass Psr6StoreTestextends TestCase

$this->store->cleanup();
}

public function testCustomCacheWithoutLockFactory(): void
Copy link
Contributor

Choose a reason for hiding this comment

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

Novoid return in test classes

Comment on lines +905 to +908
/**
* @param null $store
*/
private function getCache($store = null): TagAwareAdapterInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be more precise about the type here?

Comment on lines +821 to +822
// This test will fail if an exception is thrown, otherwise we mark it
// as passed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be on one line

@OskarStark
Copy link
Contributor

I think it makes more sense to target6.0 and introduce this new Store asexperimental. Or is it not worth, because the API is already designed and proven?

$this->locks[$cacheKey] = $this->lockFactory
->createLock($cacheKey);

return $this->locks[$cacheKey]->acquire();
Copy link
Member

Choose a reason for hiding this comment

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

if lock is not acquired, should you unsetthis->locks[$cacheKey]?

one could retry to lock the resource several time until it works

@fabpotfabpot modified the milestones:5.4,6.1Oct 29, 2021
@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@peter17
Copy link
Contributor

Any news on this topic? Anything I can do to help? Thanks

@fabpot
Copy link
Member

I'm very interested in this PR as well. I've thought a bit about the best path forward, but I'm not sure yet.
I will try to comment again soon about my thoughts.

@stof
Copy link
Member

  • The currentCachingHttpClient relies onHttpCache as well and does not support greedy caching which is something that should be supported too, imho.

To me, the mistake there was reusing the HttpCache store for the CachingHttpClient while it was designed for a reverse proxy cache, which has slightly different needs.
We will probably need to separate them at some point (we used to have a ticket about that, but I think carsonbot closed it as stale).

Toflar reacted with thumbs up emoji

@fabpot
Copy link
Member

I'm very aware of the issue@stof and this is part of my thoughts; I think I would like to start a new component that would include both types of proxies.

OskarStark and Toflar reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jderussejderussejderusse left review comments

@OskarStarkOskarStarkOskarStark left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

10 participants
@Toflar@OskarStark@peter17@fabpot@stof@jderusse@nicolas-grekas@derrabus@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp