-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Second Level Cache, QueryCache, Eviction #6096
Comments
@wtorsi why are you trying to do that? L2C should control eviction automatically (when you manipulate entities ofc). |
Ok, I'll try to describe /**
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\CategoryRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
class Category
{
/**
* @var integer
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @var Media[]
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Media", cascade={"remove"}, mappedBy="category")
* @ORM\OrderBy({"sortOrder" = "ASC"})
*/
private $medias;
} And accordingly I have /**
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\MediaRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
class Media
{
/**
* @var integer
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
private $id;
/**
* @var Category
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Category", inversedBy="medias")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $category;
} In my controller, I'm trying to get Category with Medias , sorted by sortOrder public function findByTag(bool $enabled = true)
{
$qb = $this->createQueryBuilder("c", "c.id");
$qb
->setCacheable(true)
->setCacheRegion(CategoryCache::CACHE_QUERY_CATEGORY)
->setLifetime(3600);
$qb
->leftJoin("c.medias", "m")->addSelect("m")
->where($qb->expr()->eq("c.enabled", ":enabled"))
->andWhere($qb->expr()->eq("c.tag", ":tag"))
->setParameter("enabled", $enabled)
->setParameter("tag", $tag)
->orderBy("c.sortOrder");
return $qb->getQuery()->getResult();
} Regions And now the problem. \\ Doctrine\ORM\Cache\DefaultQueryCache;
/** @var $key QueryCacheKey */
$entry = $this->region->get($key); // CacheProvider returns cached sortOrder
....
// $key with region set by root entity Category, so it is passed
if ( ! $this->validator->isValid($key, $entry)) {
$this->region->evict($key);
return null;
}
....
foreach ($entry['associations'] as $name => $assoc) {
....
foreach ($assoc['list'] as $assocIndex => $assocId) { // cached sortOrder :(
if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId))) === null) {
....
return null; //not called, and everything is ok
}
}
....
} Setting custom region for query_builder is just a solution to not clear all cache for all builders. |
Eviction non builded before queryCache is not allowed, or not performed in DefaultCache.
What is the reason for this limitation?
According to that limitation, firstly I must create cache before clearing, using getQueryCache($region) from EntityManager::$cache, like below:
What is the reason for this limitation?
The text was updated successfully, but these errors were encountered: