Varnish invalidation on subresource
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia riproducendo il comportamento della cache di Varnish con la collection /suppliers/{id}/delivery_days e una POST a /delivery_days. Traccia il servizio di invalidazione della cache e la configurazione della route della collection descritti nell’issue. Il lavoro è completato quando la cache della collection della sottorisorsa viene invalidata senza esporre una route della collection predefinita indesiderata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
API Platform version(s) affected: 3.3.6
Description
Varnish cache is not released on a subresource.
For example purposes, I use a Supplier and a DeliveryDay entity.
Supplier:
#[ORM\Entity(repositoryClass: SupplierRepository::class)]
#[ApiResource(
operations: [
new Post(),
new Get(),
new GetCollection(),
new Put(),
new Delete(),
],
normalizationContext: ['groups' => ['supplier:read']],
denormalizationContext: ['groups' => ['supplier:write']],
)]
class Supplier
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(groups: ['supplier:read'])]
private ?int $id = null;
#[ORM\Column(length: 128)]
#[Groups(groups: ['supplier:read', 'supplier:write'])]
#[Assert\NotBlank]
#[Assert\Length(max: 128)]
public string $name = '';
#[ORM\OneToMany(targetEntity: DeliveryDay::class, mappedBy: 'supplier', orphanRemoval: true)]
private Collection $deliveryDays;
public function __construct()
{
$this->deliveryDays = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, DeliveryDay>
*/
public function getDeliveryDays(): Collection
{
return $this->deliveryDays;
}
public function addDeliveryDay(DeliveryDay $deliveryDay): static
{
if (!$this->deliveryDays->contains($deliveryDay)) {
$this->deliveryDays->add($deliveryDay);
$deliveryDay->setSupplier($this);
}
return $this;
}
public function removeDeliveryDay(DeliveryDay $deliveryDay): static
{
if ($this->deliveryDays->removeElement($deliveryDay)) {
// set the owning side to null (unless already changed)
if ($deliveryDay->getSupplier() === $this) {
$deliveryDay->setSupplier(null);
}
}
return $this;
}
}
DeliveryDay:
#[ORM\Entity]
#[ApiResource(
operations: [
new Post(),
new Get(),
new GetCollection(
uriTemplate: '/suppliers/{id}/delivery_days',
uriVariables: [
'id' => new Link(
fromProperty: 'deliveryDays',
fromClass: Supplier::class
),
]
),
new Put(),
new Delete(),
],
normalizationContext: ['groups' => ['delivery_day:read']],
denormalizationContext: ['groups' => ['delivery_day:write']],
)]
class DeliveryDay
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(groups: ['delivery_day:read'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'deliveryDays')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(groups: ['delivery_day:read', 'delivery_day:write'])]
private ?Supplier $supplier = null;
#[ORM\Column(length: 64)]
#[Groups(groups: ['delivery_day:read', 'delivery_day:write'])]
#[Assert\NotBlank]
#[Assert\Length(max: 64)]
public string $day = '';
#[ORM\Column(length: 64)]
#[Groups(groups: ['delivery_day:read', 'delivery_day:write'])]
#[Assert\NotBlank]
#[Assert\Length(max: 64)]
public string $region = '';
public function getId(): ?int
{
return $this->id;
}
public function getSupplier(): ?Supplier
{
return $this->supplier;
}
public function setSupplier(?Supplier $supplier): static
{
$this->supplier = $supplier;
return $this;
}
}
How to reproduce
If you now use /suppliers/{id}/delivery_days, Varnish caches that response.
If you then make a POST request to /delivery_days, the cache from the collection route is not invalidated.
Possible Solution
If you add a default GetCollection:
new GetCollection(),
new GetCollection(
uriTemplate: '/suppliers/{id}/delivery_days',
uriVariables: [
'id' => new Link(
fromProperty: 'deliveryDays',
fromClass: Supplier::class
),
]
),
It works, but then there is a route exposed that you don't really want.
So, I would suggest always adding a default cache tag to a collection.
In this case, that would be /delivery_days (even when the route doesn't exist)
and also add this tag to the invalidation service (even if the route doesn't exist).
end word
If I'm doing something that is not intended or missed some docs, please point me in the right direction.
I would like to help resolve this issue by contributing, but I have never done that before.
I would appreciate some help or guidance to get started.
- Lingua principale
- PHP
- Stelle
- 2.6k
- Fork
- 989
- Merge medio
- 2g 1h
- PR unite (30g)
- 104
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/core
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Forse già presa @ousamabenyounes l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 80/100
api-platform/core#8701 ·
I maintainer di solito rispondono entro 1 giorno
-
JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
api-platform/core#8699 ·
I maintainer di solito rispondono entro 1 giorno
-
api:openapi:export --spec-version=3.0.0 outputs `webhooks`, which is invalid in OpenAPI 3.0Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
api-platform/core#8690 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
api-platform/core#8680 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
api-platform/core#8725 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di api-platform/core
Issue simili
-
PHP workflow streaming requests buffer the full SSE responseForse già presa @Winoren l’ha presa oggi. Apertareview: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
langgenius/dify#44270 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
bug customer-reported
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
MagnaCapax/PMSS#1085 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
nunomaduro/collision#375 ·
-
enhancement good first issue hacktoberfest help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
thetheago/laravel-seeder-versioning#19 ·
I maintainer di solito rispondono entro 1 giorno