-
Notifications
You must be signed in to change notification settings - Fork 11
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
Cache refactor #452
base: release/10.0.0
Are you sure you want to change the base?
Cache refactor #452
Conversation
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.
Nice work 👏🏼
Left one suggestion
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.
Nice work 👏🏼
Left a suggestion and a question
WP_CLI::log('Database search replace for host successfully finished.'); | ||
WP_CLI::log('--------------------------------------------------'); | ||
|
||
// Search and replace url scheme. |
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.
// Search and replace url scheme. | |
// Search and replace URL scheme. |
@@ -84,15 +88,14 @@ class Helpers | |||
* @var array<int, string> | |||
*/ | |||
private const PROJECT_RENDER_ALLOWED_NAMES = [ | |||
'src', | |||
'blocksRoot', |
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.
Do we need this here blocksRoot
?
try { | ||
if (isset($this->manifestCache)) { | ||
$serviceClasses = $this->manifestCache->getCacheTopItem('serviceClasses', AbstractManifestCache::TYPE_SERVICES, isJson: false); | ||
if ($serviceClasses) { | ||
return $serviceClasses; | ||
} | ||
} | ||
} catch (InvalidManifest) { | ||
// ignored, cache is simply not set. | ||
} | ||
|
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.
So service class caching will be entirely removed?
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.
no, ti will be stored as a file cache like DI container
/** | ||
* Create the service classes cache file and return the services array. | ||
* | ||
* @param array<string, mixed> $services Array of services. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
private function createServiceClassesCacheFile(array $services): array | ||
{ | ||
if (Helpers::shouldCache()) { | ||
$sep = \DIRECTORY_SEPARATOR; | ||
$file = \explode('\\', $this->namespace); | ||
|
||
$cacheFolder = $this->getCachedFolderPath(); | ||
$cacheFile = "{$cacheFolder}{$sep}{$file[0]}ServiceClasses.json"; | ||
|
||
if (\file_exists($cacheFile)) { | ||
return \json_decode(\file_get_contents($cacheFile), true); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | ||
} | ||
|
||
if (!\file_exists($cacheFolder)) { | ||
\mkdir($cacheFolder, 0755, true); | ||
} | ||
|
||
\file_put_contents( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents | ||
$cacheFile, | ||
\wp_json_encode($services) | ||
); | ||
|
||
return $services; | ||
} | ||
|
||
return $services; | ||
} |
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.
Ah, I see, it's now cached to a file. But where is this used? What does the flow look like now?
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.
by default under vendor-prefixed/infinum/eightshift-libs/src/Main/Cache
but you can use global contant to change the cache folder location if you have any issues with folder write permissions.
define('EIGHTSHIFT_DI_CACHE_FOLDER', ABSPATH . 'eightshift-di-cache');
- this will store the cache in the project root
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.
ok I will have to read this in more depth to understand how it works, thx
Description
PROJECT_RENDER_ALLOWED_NAMES
variables.getManifestByDir
methodrenderPartial
,getManifest
methods.