Core: Cache not updated when entity annotation is changed

Created on 25 Mar 2019  路  12Comments  路  Source: api-platform/core

This morning, I started a new project with API Platform v2.4, and almost from scratch, I had to clear the cache to get my API documentation updated.

Steps to reproduce

Create a new Symfony application api-platform-issue symfony new --full api-platform-issue.

Go to this new project (cd api-platform-issue).

Install API platform by using composer req api.

Install embedded web server composer req server and start it bin/console server:run.

Open API doc: http://localhost:8000/api

Create an entity Pizza:

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ApiResource
 * @ORM\Entity
 */
class Pizza
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     *
     * @var int
     */
    private $id;

    public function getId(): ?int
    {
        return $this->id;
    }
}

Refresh your API doc, you don't see any change.

Delete your cache (rm -rf var/cache).

API is updated.

Further steps

If you delete the annotation and update cache, you'll see no change.

Environment details

Bug reproduced:

  • With a docker environment (PHP 7.3)
  • With my local PHP setup (PHP 7.2)

All 12 comments

Probably related to https://github.com/api-platform/core/pull/2629... @teohhanhui can you take a look? Maybe should we revert this patch until it is properly tested and "edge cases" (this one is a basic case) are handled properly.

This is even more related to #2593 and it's not easy to take a decision that will not have an impact.

I prefer to favor DX than performance in dev env.

~Symfony uses cache in dev environment out of the box. We should do the same. If we require more manual cache:clear, then that's something we should fix.~

So we are back at square 1 with a lot of things to improve performance as it's so poor right now it's a also DX problem.

@bastnic Unfortunately, yeah...

About this case you can still use metadata_cache=true in your configuration but yeah...

@bastnic in the meantime you can set api_platform.metadata_cache to true if you don't mind running cache:clear manually. But I'm sure there are rooms for improvements that doesn't hurt DX.

If I remember correctly, the main issues are:

  • parsing to get which property is the identifier
  • reconstruct all the routing on each requests
  • that there is no static cache whatsoever when it's disabled and so we do all these heavy operations again and again.

I'll look into it.

Closing as it's been reverted in #2648, but I'll look into https://github.com/api-platform/core/issues/2644#issuecomment-476205943

Was this page helpful?
0 / 5 - 0 ratings