-
-
Notifications
You must be signed in to change notification settings - Fork 1
Preload results in in-memory cache; Rename Cache -> FileCache
#8
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
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
14826ab
Implement in-memory cache; Rename `Cache` -> `FileCache`
tangrufus 07c0db8
Warm cache in batch
tangrufus 0a60e6e
:robot: `pint`
tangrufus f552e63
Make `FileCache` a `readonly` class
tangrufus 719b7a8
Test `CacheProxy`
tangrufus 22173d9
Merge remote-tracking branch 'origin/main' into memory
tangrufus 6d2725c
Test `ArrayCache`
tangrufus eda96f8
Merge remote-tracking branch 'origin/main' into memory
tangrufus 0b493d3
Test `ArrayCache`, `CacheProxy` & `FileCache` implements `CacheInterf…
tangrufus 2d50116
Fix typo
tangrufus a640e89
Merge remote-tracking branch 'origin/main' into memory
tangrufus 0a2cc9d
Merge branch 'main' into memory
tangrufus 2d0b0c2
Merge branch 'main' into memory
tangrufus d6b48f8
Merge branch 'main' into memory
tangrufus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace TypistTech\WpOrgClosedPlugin\WpOrg\Api; | ||
|
|
||
| class ArrayCache implements CacheInterface | ||
| { | ||
| /** @var array<string, bool> */ | ||
| private array $data = []; | ||
|
|
||
| public function read(string $slug): ?bool | ||
| { | ||
| return $this->data[$slug] ?? null; | ||
| } | ||
|
|
||
| public function write(string $slug, bool $isClosed): void | ||
| { | ||
| $this->data[$slug] = $isClosed; | ||
| } | ||
| } |
This file contains hidden or 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,12 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace TypistTech\WpOrgClosedPlugin\WpOrg\Api; | ||
|
|
||
| interface CacheInterface | ||
| { | ||
| public function read(string $slug): ?bool; | ||
|
|
||
| public function write(string $slug, bool $isClosed): void; | ||
| } |
This file contains hidden or 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,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace TypistTech\WpOrgClosedPlugin\WpOrg\Api; | ||
|
|
||
| readonly class CacheProxy implements CacheInterface | ||
| { | ||
| public function __construct( | ||
| private CacheInterface $fast, | ||
| private CacheInterface $slow, | ||
| ) {} | ||
|
|
||
| public function read(string $slug): ?bool | ||
| { | ||
| $result = $this->fast->read($slug); | ||
| if ($result !== null) { | ||
| return $result; | ||
| } | ||
|
|
||
| $result = $this->slow->read($slug); | ||
| if ($result !== null) { | ||
| $this->fast->write($slug, $result); | ||
| } | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| public function write(string $slug, bool $isClosed): void | ||
| { | ||
| $this->fast->write($slug, $isClosed); | ||
| $this->slow->write($slug, $isClosed); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Unit\WpOrg\Api; | ||
|
|
||
| use TypistTech\WpOrgClosedPlugin\WpOrg\Api\ArrayCache; | ||
| use TypistTech\WpOrgClosedPlugin\WpOrg\Api\CacheInterface; | ||
|
|
||
| covers(ArrayCache::class); | ||
|
|
||
| describe(ArrayCache::class, static function (): void { | ||
| it('implements CacheInterface', function (): void { | ||
| $cache = new ArrayCache; | ||
|
|
||
| expect($cache)->toBeInstanceOf(CacheInterface::class); | ||
| }); | ||
|
|
||
| describe('::read()', static function (): void { | ||
| test('hit', function (bool $expected): void { | ||
| $cache = new ArrayCache; | ||
| $cache->write('foo', $expected); | ||
|
|
||
| $actual = $cache->read('foo'); | ||
|
|
||
| expect($actual)->toBe($expected); | ||
| })->with([true, false]); | ||
|
|
||
| test('miss', function (): void { | ||
| $cache = new ArrayCache; | ||
|
|
||
| $actual = $cache->read('foo'); | ||
|
|
||
| expect($actual)->toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('::write()', static function (): void { | ||
| it('stores', function (bool $isClosed): void { | ||
| $cache = new ArrayCache; | ||
|
|
||
| $cache->write('foo', $isClosed); | ||
|
|
||
| expect($cache->read('foo'))->toBe($isClosed); | ||
| })->with([true, false]); | ||
|
|
||
| test('last write wins', function (bool $first, bool $last): void { | ||
| $cache = new ArrayCache; | ||
|
|
||
| $cache->write('foo', $first); | ||
| $cache->write('foo', $last); | ||
|
|
||
| expect($cache->read('foo'))->toBe($last); | ||
| })->with([ | ||
| [true, false], | ||
| [false, true], | ||
| [true, true], | ||
| [false, false], | ||
| ]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help wanted!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually install ~100 wp.org plugins and look at the cache generation, it feels like the promises are performed concurrently.
Still don't have a way to assert it pragmatically