Updated cache evict policy on data updates

Change-Id: I2b4ea68e7b9b198239c1055099b0d7159db4291c
This commit is contained in:
Sebastian Marcet 2017-03-13 21:28:33 -03:00
parent aeb15ac0ca
commit 2481b246c6
17 changed files with 62 additions and 7 deletions

View File

@ -48,6 +48,10 @@ final class SummitEntityEventSerializer extends SilverStripeSerializer
$params
);
}
if($values['class_name'] == 'PresentationType')
$values['class_name'] = 'SummitEventType';
return $values;
}
}

View File

@ -12,8 +12,11 @@
* limitations under the License.
**/
use Illuminate\Support\Facades\Log;
use models\summit\SummitEntityEvent;
use models\utils\IEntity;
use LaravelDoctrine\ORM\Facades\Registry;
use Doctrine\ORM\EntityManager;
/**
* Class EntityEventType
@ -21,6 +24,8 @@ use models\utils\IEntity;
*/
abstract class EntityEventType implements IEntityEventType
{
const EntityManager = 'ss';
/**
* @var SummitEntityEvent
*/
@ -46,4 +51,35 @@ abstract class EntityEventType implements IEntityEventType
* @return IEntity|null
*/
abstract protected function registerEntity();
/**
* @return EntityManager
*/
protected function getEM(){
return Registry::getManager(self::EntityManager);
}
protected function getLocalClassName(){
$class_name = $this->entity_event->getEntityClassName();
switch ($class_name){
case 'MySchedule':
case 'MyFavorite':
return 'models\summit\SummitEvent';
break;
case 'PresentationType':
return 'models\summit\SummitEventType';
break;
}
return sprintf('models\summit\%s',$class_name);
}
protected function evictEntity(){
$cache = $this->getEM()->getCache();
$class_name = $this->getLocalClassName();
if(!is_null($cache) && !empty($class_name) && $cache->containsEntity($class_name, $this->entity_event->getEntityId())) {
$cache->evictEntity($class_name, $this->entity_event->getEntityId());
Log::debug(sprintf("class_name % - id %s evicted from 2nd level cache", $class_name, $this->entity_event->getEntityId()));
}
}
}

View File

@ -79,6 +79,7 @@ final class EntityEventTypeFactory
}
break;
case 'SummitEventType':
case 'PresentationType':
{
return new SummitEventTypeEntityEventType($e, $ctx);
}
@ -121,6 +122,7 @@ final class EntityEventTypeFactory
}
break;
case 'PresentationCategoryGroup':
case 'PrivatePresentationCategoryGroup':
{
return new PresentationCategoryGroupEntityEventType($e, $ctx);
}

View File

@ -1,4 +1,4 @@
<?php
<?php namespace Models\foundation\summit\EntityEvents;
/**
* Copyright 2016 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -12,8 +12,6 @@
* limitations under the License.
**/
namespace Models\foundation\summit\EntityEvents;
/**
* Class GenericSummitEntityEventType
* @package Models\foundation\summit\EntityEvents
@ -33,4 +31,5 @@ abstract class GenericSummitEntityEventType extends EntityEventType
}
$this->process_ctx->registerEntityEvent($this->entity_event);
}
}

View File

@ -24,6 +24,7 @@ final class PresentationCategoryEntityEventType extends GenericSummitEntityEvent
*/
protected function registerEntity()
{
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getPresentationCategory($this->entity_event->getEntityId());
if(is_null($entity)) return null;
$this->entity_event->registerEntity($entity);

View File

@ -26,6 +26,7 @@ final class PresentationCategoryGroupEntityEventType extends GenericSummitEntity
*/
protected function registerEntity()
{
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getCategoryGroup($this->entity_event->getEntityId());
if(is_null($entity)) return null;
$this->entity_event->registerEntity($entity);

View File

@ -29,6 +29,7 @@ final class PresentationMaterialEntityEventType extends GenericSummitEntityEvent
if(!isset($metadata['presentation_id'])) return null;
$presentation = $this->entity_event->getSummit()->getScheduleEvent(intval($metadata['presentation_id']));
if (is_null($presentation)) return null;
$this->evictEntity();
$material = $presentation->getMaterial($this->entity_event->getEntityId());
if(is_null($material)) return null;
$this->entity_event->registerEntity($material);

View File

@ -26,6 +26,7 @@ final class PresentationSpeakerEntityEventType extends GenericSummitEntityEventT
*/
protected function registerEntity()
{
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getSpeaker($this->entity_event->getEntityId());
if(!is_null($entity))
$this->entity_event->registerEntity($entity);

View File

@ -26,6 +26,7 @@ final class SummitEntityEventType extends GenericSummitEntityEventType
*/
protected function registerEntity()
{
$this->evictEntity();
$summit = $this->entity_event->getSummit();
if(is_null($summit)) return null;
if($summit->getId() !== $this->entity_event->getEntityId()) return null;

View File

@ -33,6 +33,7 @@ abstract class SummitEventEntityEventType extends EntityEventType
* @return SummitEvent|null
*/
protected function getEntity(){
$this->evictEntity();
return $this->entity_event->getSummit()->getScheduleEvent($this->entity_event->getEntityId());
}
}

View File

@ -25,6 +25,7 @@ final class SummitEventTypeEntityEventType extends GenericSummitEntityEventType
*/
protected function registerEntity()
{
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getEventType($this->entity_event->getEntityId());
if(!is_null($entity))
$this->entity_event->registerEntity($entity);

View File

@ -30,6 +30,7 @@ final class SummitLocationEntityEventType extends GenericSummitEntityEventType
$type = $this->entity_event->getType();
// if there is an insert in place, skip it
if($type === 'UPDATE' && $this->process_ctx->existsInsertOp($this->entity_event)) return null;
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getLocation($this->entity_event->getEntityId());
if(is_null($entity)) return null;
return $this->entity_event->registerEntity($entity);

View File

@ -29,6 +29,7 @@ final class SummitLocationImageEventType extends GenericSummitEntityEventType
if(!isset($metadata['location_id'])) return null;
$location = $this->entity_event->getSummit()->getLocation(intval($metadata['location_id']));
if(is_null($location)) return null;
$this->evictEntity();
$entity = $location->getImage($this->entity_event->getEntityId());
if(is_null($entity)) return null;
$this->entity_event->registerEntity($entity);

View File

@ -25,6 +25,7 @@ final class SummitTicketTypeEntityEventType extends GenericSummitEntityEventType
*/
protected function registerEntity()
{
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getTicketType($this->entity_event->getEntityId());
if(!is_null($entity))
$this->entity_event->registerEntity($entity);

View File

@ -27,6 +27,7 @@ final class SummitVenueFloorEntityEventType extends GenericSummitEntityEventType
{
$metadata = $this->entity_event->getMetadata();
if(!isset($metadata['venue_id'])) return null;
$this->evictEntity();
$location = $this->entity_event->getSummit()->getLocation(intval($metadata['venue_id']));
if (is_null($location)) return null;
$floor = $location->getFloor($this->entity_event->getEntityId());

View File

@ -26,6 +26,7 @@ class SummitWIFIConnectionEntityEventType extends GenericSummitEntityEventType
*/
protected function registerEntity()
{
$this->evictEntity();
$entity = $this->entity_event->getSummit()->getWifiConnection($this->entity_event->getEntityId());
if(!is_null($entity))
$this->entity_event->registerEntity($entity);

View File

@ -134,13 +134,13 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$this->assertResponseStatus(200);
}
public function testGetCurrentSummit()
public function testGetCurrentSummit($summit_id = 22)
{
$params = array
(
'expand' => 'schedule',
'id' => 6
'id' => $summit_id
);
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
@ -1214,11 +1214,13 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
public function testGetEntityEventsFromCurrentSummit()
{
//$this->testGetCurrentSummit(22);
$params = array
(
'id' => '7',
'id' => '22',
'from_date' => 1460148342,
'limit' => 100
'limit' => 100
);
$headers = array