[DDC-2295] [GH-580] Second cache level POC Created: 14/Feb/13 Updated: 14/Mar/13 |
|
| Status: | Open |
| Project: | Doctrine 2 - ORM |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | New Feature | Priority: | Major |
| Reporter: | Benjamin Eberlei | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
This issue is created automatically through a Github pull request on behalf of FabioBatSilva: Url: https://github.com/doctrine/doctrine2/pull/580 Message: Hi guys. After a look into some implementations I end up with the following solution for the second level cache.. There is lot of work todo before merge it, but i'd like to get your thoughts before i go any further on this approach.
Collection Caching The most common use case is to cache entities. But we can also cache relationships. Only identifiers will be cached for collection. When a collection is read from the second level cache it will create proxies based on the cached identifiers, if the application needs to access an element, Doctrine will go to the cache to load the element data.
*********************************************************************************************
*********************************************************************************************
*********************************************************************************************
```php <?php /** * @Entity * @Cache("NONSTRICT_READ_WRITE") */ class State { /** * @Id * @GeneratedValue * @Column(type="integer") */ protected $id; /** * @Column */ protected $name; /** * @Cache() * @ManyToOne(targetEntity="Country") * @JoinColumn(name="country_id", referencedColumnName="id") */ protected $country; /** * @Cache() * @OneToMany(targetEntity="City", mappedBy="state") */ protected $cities; } ``` ```php <?php $em->persist(new State($name, $country)); $em->flush(); // Put into cache $em->clear(); // Clear entity manager $state = $em->find('Entity\State', 1); // Retreive item from cache $country = $state->getCountry(); // Retreive item from cache $cities = $state->getCities(); // Load from database and put into cache $state->setName("New Name"); $em->persist($state); $em->flush(); // Update item cache $em->clear(); // Clear entity manager $em->find('Entity\State', 1)->getCities(); // Retreive from cache $em->getCache()->containsEntity('Entity\State', $state->getId()) // Check if the cache exists $em->getCache()->evictEntity('Entity\State', $state->getId()); // Remove an entity from cache $em->getCache()->evictEntityRegion('Entity\State'); // Remove all entities from cache $em->getCache()->containsCollection('Entity\State', 'cities', $state->getId()); // Check if the cache exists $em->getCache()->evictCollection('Entity\State', 'cities', $state->getId()); // Remove an entity collection from cache $em->getCache()->evictCollectionRegion('Entity\State', 'cities'); // Remove all collections from cache ```
|