Extracted ony the common logic
This commit is contained in:
parent
50ef1369c3
commit
12b5a0cdd7
@ -31,22 +31,34 @@ use Doctrine\ORM\Cache\EntityCacheKey;
|
|||||||
*/
|
*/
|
||||||
class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $isChanged = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function afterTransactionComplete()
|
public function afterTransactionComplete()
|
||||||
{
|
{
|
||||||
foreach (array('insert', 'update', 'delete') as $type) {
|
$isChanged = false;
|
||||||
$this->handleCache($type);
|
|
||||||
|
if (isset($this->queuedCache['insert'])) {
|
||||||
|
foreach ($this->queuedCache['insert'] as $entity) {
|
||||||
|
$isChanged = $this->putCache($entity, $isChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isChanged) {
|
if (isset($this->queuedCache['update'])) {
|
||||||
|
foreach ($this->queuedCache['update'] as $entity) {
|
||||||
|
$isChanged = $this->putCache($entity, $isChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->queuedCache['delete'])) {
|
||||||
|
foreach ($this->queuedCache['delete'] as $key) {
|
||||||
|
$this->region->evict($key);
|
||||||
|
|
||||||
|
$isChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isChanged) {
|
||||||
$this->timestampRegion->update($this->timestampKey);
|
$this->timestampRegion->update($this->timestampKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +80,7 @@ class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
|||||||
{
|
{
|
||||||
$this->persister->delete($entity);
|
$this->persister->delete($entity);
|
||||||
|
|
||||||
$this->queuedCache['delete'][] = new EntityCacheKey(
|
$this->queuedCache['delete'][] = new EntityCacheKey($this->class->rootEntityName, $this->uow->getEntityIdentifier($entity));
|
||||||
$this->class->rootEntityName,
|
|
||||||
$this->uow->getEntityIdentifier($entity)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,39 +93,24 @@ class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
|||||||
$this->queuedCache['update'][] = $entity;
|
$this->queuedCache['update'][] = $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleCache($type)
|
private function putCache($entity, $isChanged)
|
||||||
{
|
{
|
||||||
if (!isset($this->queuedCache[$type])) {
|
$class = $this->class;
|
||||||
return;
|
$className = ClassUtils::getClass($entity);
|
||||||
|
|
||||||
|
if ($className !== $this->class->name) {
|
||||||
|
$class = $this->metadataFactory->getMetadataFor($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($type, array('insert', 'update'))) {
|
$key = new EntityCacheKey($class->rootEntityName, $this->uow->getEntityIdentifier($entity));
|
||||||
foreach ($this->queuedCache[$type] as $entity) {
|
$entry = $this->hydrator->buildCacheEntry($class, $key, $entity);
|
||||||
$class = $this->class;
|
$cached = $this->region->put($key, $entry);
|
||||||
$className = ClassUtils::getClass($entity);
|
$isChanged = $isChanged ?: $cached;
|
||||||
|
|
||||||
if ($className !== $this->class->name) {
|
if ($this->cacheLogger && $cached) {
|
||||||
$class = $this->metadataFactory->getMetadataFor($className);
|
$this->cacheLogger->entityCachePut($this->regionName, $key);
|
||||||
}
|
|
||||||
|
|
||||||
$key = new EntityCacheKey($class->rootEntityName, $this->uow->getEntityIdentifier($entity));
|
|
||||||
$entry = $this->hydrator->buildCacheEntry($class, $key, $entity);
|
|
||||||
$cached = $this->region->put($key, $entry);
|
|
||||||
$this->isChanged = $this->isChanged ?: $cached;
|
|
||||||
if ($this->cacheLogger && $cached) {
|
|
||||||
$this->cacheLogger->entityCachePut($this->regionName, $key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('delete' === $type) {
|
return $isChanged;
|
||||||
foreach ($this->queuedCache['delete'] as $key) {
|
|
||||||
$this->region->evict($key);
|
|
||||||
|
|
||||||
$this->isChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user