From 80c94082f836be8507eac4eb8ef4aededad184db Mon Sep 17 00:00:00 2001 From: Ollie Read Date: Sun, 28 Jun 2020 16:54:06 +0100 Subject: [PATCH 1/2] Update testbench dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2d433e9..04ff52a 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "laravel/framework": "^7.0" }, "require-dev": { - "orchestra/testbench": "^4.0" + "orchestra/testbench": "^5.0" }, "extra": { "laravel": { From 63b0fd293335c35b5e6ac22430c2c6b45206ab62 Mon Sep 17 00:00:00 2001 From: Ollie Read Date: Sun, 28 Jun 2020 16:57:22 +0100 Subject: [PATCH 2/2] Add ability to flush identity map --- CHANGELOG.md | 4 ++++ README.md | 5 +++++ src/IdentityManager.php | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b88953d..0a5ac21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Change `orchestra/testbench` version to match Laravel version. +### Added +- Added a `IdentityManager::flushIdentities()` method to clear the identity map. ## [1.0.0] - 2020-06-24 - Initial release diff --git a/README.md b/README.md index 0d4e76c..183c03a 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ using the Identity Map design pattern ([P of EAA](https://martinfowler.com/eaaCa - [Finding](#finding) - [Hydrating](#hydrating) - [Belongs To](#belongsto) + - [Flushing](#flushing) - [How does it work](#how) - [Why?](#why) @@ -68,6 +69,10 @@ updated, but will retain any changes you'd previously made. If a belongs to relationship is loaded (not belongs to many) without constraints and without `refreshIdentityMap()` being called, the query will skip any model instances that already exist. +### Flushing +If you wish to flush the cached models, call `flushIdentities()` on an instance of `IdentityManager`, or on the `Eloquence` +facade. + ## How The `IdentityManager` stores an array containing all existing model instances and their identity. diff --git a/src/IdentityManager.php b/src/IdentityManager.php index a762afe..81c0ea9 100644 --- a/src/IdentityManager.php +++ b/src/IdentityManager.php @@ -94,6 +94,18 @@ public function removeIdentity(ModelIdentity $identity): IdentityManager return $this; } + /** + * Remove all models from the identity map. + * + * @return $this + */ + public function flushIdentities(): IdentityManager + { + $this->models = []; + + return $this; + } + /** * Get all stored identities. *