forked from thephpleague/flysystem-cached-adapter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove array caching to prevent always returning miss from memory (#3) (
#5) Co-authored-by: Rick Kuipers <[email protected]>
- Loading branch information
Showing
4 changed files
with
61 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace tests\jgivoni\Flysystem\Cache; | ||
|
||
use jgivoni\Flysystem\Cache\CacheItemsTrait; | ||
use League\Flysystem\FileAttributes; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Cache\CacheItemInterface; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
|
||
class CacheItemsTrait_Test extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function return_hit_after_miss(): void | ||
{ | ||
$adapter = new class { | ||
use CacheItemsTrait; | ||
|
||
public function __construct( | ||
protected readonly CacheItemPoolInterface $cache = new ArrayAdapter() | ||
) { | ||
} | ||
|
||
public function getItem(string $path): CacheItemInterface | ||
{ | ||
return $this->getCacheItem($path); | ||
} | ||
|
||
public function saveItem(CacheItemInterface $item): void | ||
{ | ||
$this->saveCacheItem($item); | ||
} | ||
}; | ||
|
||
$path = 'test.txt'; | ||
$item = $adapter->getItem($path); | ||
|
||
self::assertFalse($item->isHit()); | ||
|
||
$item->set(new FileAttributes( | ||
path: $path | ||
)); | ||
|
||
$adapter->saveItem($item); | ||
|
||
$freshItem = $adapter->getItem($path); | ||
self::assertTrue($freshItem->isHit()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters