Skip to content

Commit 26f4c9a

Browse files
committed
Added test to ensure CacheItemPool is not cloned in CachingConnector.
Removed note in Readme about caching not being supported.
1 parent 291d172 commit 26f4c9a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ Any connector can be wrapped in a `CachingConnector` to provide [PSR-6][] cachin
290290

291291
Remember that whilst using a `CachingConnector` enables caching, caching must also be enabled on a per-import basis by calling `Import::enableCache()`.
292292

293-
Note that Caching is not yet supported for asynchronous imports.
294-
295293
### Example
296294

297295
The follow example enables connector caching.

src/Provider/Provider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface Provider
1212
{
1313
/**
1414
* Gets a connector compatible with this provider's resources.
15+
*
16+
* NB: this should not be a factory method as it will break things like caching.
1517
*/
1618
public function getConnector(): Connector;
1719
}

test/Integration/Connector/CachingConnectorTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testCacheBypassedForDifferentOptions(): void
6565
}
6666

6767
/**
68-
* That that when the generated cache key contains non-compliant PSR-6 characters,
68+
* Tests that when the generated cache key contains non-compliant PSR-6 characters,
6969
* InvalidCacheKeyException is thrown.
7070
*/
7171
public function testValidateCacheKey(): void
@@ -88,10 +88,26 @@ public function testGetWrappedConnector(): void
8888
/**
8989
* Tests that cloning the caching connector also clones the wrapped connector.
9090
*/
91-
public function testClone(): void
91+
public function testCloneConnector(): void
9292
{
9393
$clone = clone $this->connector;
9494

9595
self::assertNotSame($this->wrappedConnector, $clone->getWrappedConnector());
9696
}
97+
98+
/**
99+
* Tests that cloning the caching connector does not clone the cache item pool (both instances point to the same
100+
* pool).
101+
*/
102+
public function testCloneCacheItemPool(): void
103+
{
104+
$clone = clone $this->connector;
105+
106+
$cacheA = \Closure::bind(fn () => $this->cache, $this->connector, $this->connector)();
107+
$cacheB = \Closure::bind(fn () => $this->cache, $clone, $clone)();
108+
self::assertSame($cacheA, $cacheB);
109+
110+
$clone->fetch($this->source);
111+
self::assertSame(1, $cacheA->count(), 'Fetch on clone updates original cache item pool.');
112+
}
97113
}

0 commit comments

Comments
 (0)