Last active
August 29, 2015 14:23
-
-
Save guiwoda/930648464254dbaff269 to your computer and use it in GitHub Desktop.
Invalidating association second level cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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