-
-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(laravel): cache metadata, add trace on debug mode (#6555)
- Loading branch information
Showing
8 changed files
with
311 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Laravel\Metadata; | ||
|
||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
final readonly class CachePropertyMetadataFactory implements PropertyMetadataFactoryInterface | ||
{ | ||
public function __construct( | ||
private PropertyMetadataFactoryInterface $decorated, | ||
private string $cacheStore | ||
) { | ||
} | ||
|
||
public function create(string $resourceClass, string $property, array $options = []): ApiProperty | ||
{ | ||
$key = hash('xxh3', serialize(['resource_class' => $resourceClass, 'property' => $property] + $options)); | ||
|
||
return Cache::store($this->cacheStore)->rememberForever($key, function () use ($resourceClass, $property, $options) { | ||
return $this->decorated->create($resourceClass, $property, $options); | ||
}); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Laravel/Metadata/CachePropertyNameCollectionMetadataFactory.php
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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Laravel\Metadata; | ||
|
||
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; | ||
use ApiPlatform\Metadata\Property\PropertyNameCollection; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
final readonly class CachePropertyNameCollectionMetadataFactory implements PropertyNameCollectionFactoryInterface | ||
{ | ||
public function __construct( | ||
private PropertyNameCollectionFactoryInterface $decorated, | ||
private string $cacheStore | ||
) { | ||
} | ||
|
||
public function create(string $resourceClass, array $options = []): PropertyNameCollection | ||
{ | ||
$key = hash('xxh3', serialize(['resource_class' => $resourceClass] + $options)); | ||
|
||
return Cache::store($this->cacheStore)->rememberForever($key, function () use ($resourceClass, $options) { | ||
return $this->decorated->create($resourceClass, $options); | ||
}); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Laravel/Metadata/CacheResourceCollectionMetadataFactory.php
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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Laravel\Metadata; | ||
|
||
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; | ||
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
final readonly class CacheResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface | ||
{ | ||
public function __construct( | ||
private ResourceMetadataCollectionFactoryInterface $decorated, | ||
private string $cacheStore | ||
) { | ||
} | ||
|
||
public function create(string $resourceClass): ResourceMetadataCollection | ||
{ | ||
return Cache::store($this->cacheStore)->rememberForever($resourceClass, function () use ($resourceClass) { | ||
return $this->decorated->create($resourceClass); | ||
}); | ||
} | ||
} |
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