Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to clear the EntityCache #121

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/System/EntityCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EntityCache

/**
* Entity Map for the current Entity Type
* @var [type]
* @var \Analogue\ORM\EntityMap
*/
protected $entityMap;

Expand Down Expand Up @@ -143,9 +143,9 @@ public function cacheLoadedRelationResult($parent, $relation, $results, Relation
/**
* Create a cachedRelationship instance which will hold related entity's hash and pivot attributes, if any.
*
* @param $parentKey
* @param string $parentKey
* @param string $relation
* @param $result
* @param array $result
* @param Relationship $relationship
* @throws MappingException
* @return CachedRelationship
Expand Down Expand Up @@ -295,7 +295,9 @@ protected function transform(Aggregate $aggregatedEntity)
}

/**
* @param $relation
* Get pivot attributes for a relation
*
* @param string $relation
* @param InternallyMappable $entity
* @return array
*/
Expand All @@ -315,4 +317,17 @@ protected function getPivotValues($relation, InternallyMappable $entity)

return $values;
}

/**
* Clear the entity Cache. Use with caution as it could result
* in impredictable behaviour if the cached entities are stored
* after the cache clear operation.
*
* @return void
*/
public function clear()
{
$this->cache = [];
$this->pivotAttributes = [];
}
}