Skip to content

Instantly share code, notes, and snippets.

@guiwoda
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guiwoda/930648464254dbaff269 to your computer and use it in GitHub Desktop.
Save guiwoda/930648464254dbaff269 to your computer and use it in GitHub Desktop.
Invalidating association second level cache
<?php namespace App\Entities;
// IGNORE THE CONFIGURATION DETAILS :-)
/**
* @Entity
* @Cache(usage="NONSTRICT_READ_WRITE")
*/
class Post {
/**
* @Cache("NONSTRICT_READ_WRITE")
* @OneToMany(targetEntity="App\Entities\Comment", mappedBy="post", cascade={"all"})
*/
private $comments;
public function addComment(Comment $comment)
{
$this->comments->add($comment);
}
}
/**
* @Entity
* @Cache(usage="NONSTRICT_READ_WRITE")
*/
class Comment {
/**
* @Cache("NONSTRICT_READ_WRITE")
* @ManyToOne(targetEntity="App\Entities\Post")
*/
private $post;
}
<?php
$user = $entityManager->find(App\Entities\User::class, 1);
$post = $entityManager->find(App\Entities\Post::class, 1);
$comment = new App\Entities\Comment($user, $post, 'Hello world!');
$post->addComment($comment);
// Should this be enough to invalidate $post->comments ?
$entityManager->persist($post);
$entityManager->flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment