diff --git a/docs/components/cache/adapters.md b/docs/components/cache/adapters.md index 719f7666..0f2875aa 100644 --- a/docs/components/cache/adapters.md +++ b/docs/components/cache/adapters.md @@ -17,6 +17,9 @@ Requires the APCu extension is loaded and enabled. use SonsOfPHP\Componenet\Cache\Adapter\ApcuAdapter; $cache = new ApcuAdapter(); + +// You can set a default TTL in seconds and Marshaller as well. +$cache = new ApcuAdapter(60, new CustomMarshaller()); ``` ## ArrayAdapter @@ -49,6 +52,22 @@ $cache = new ChainAdapter([ ]); ``` +## FilesystemAdapter + +Stores cache files on disk + +```php + ['contains@reserved}characters']; } + + public function testItCanReturnExpiry(): void + { + $item = new CacheItem('testing'); + $this->assertNull($item->expiry()); + $item->expiresAfter(3600); + $this->assertNotNull($item->expiry()); + } } diff --git a/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php b/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php index c3b1e28f..dea59f3c 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php @@ -145,4 +145,18 @@ public function testGetMultiple(): void $this->assertSame('default.value', $items['item.key']); $this->assertSame('item2.value', $items['item2']); } + + public function testItWillSaveWhenTTLIsSet(): void + { + $item = $this->createMock(CacheItemInterface::class); + $item->expects($this->once())->method('set'); + $item->expects($this->once())->method('expiresAfter'); + + $this->adapter->expects($this->once())->method('getItem')->willReturn($item); + $this->adapter->expects($this->once())->method('save')->willReturn(true); + + $cache = new SimpleCache($this->adapter); + + $this->assertTrue($cache->set('item.key', 'item.value', 60)); + } }