Skip to content
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

Open
wants to merge 13 commits into
base: release/10.0.0
Choose a base branch
from
Open

Cache refactor #452

wants to merge 13 commits into from

Conversation

iruzevic
Copy link
Member

@iruzevic iruzevic commented Feb 20, 2025

Description

  • Restructuring caching system for manifest.
  • Updating helpers for blocks.
  • Fixing issues with linters.
  • Simplifying blocks registration.
  • Caching service classes to file like DI container
  • refactoring render method to pass manifest and globalManifest variable to all content
  • refactoring getProjectPaths method for simpler usage
  • changing PROJECT_RENDER_ALLOWED_NAMES variables.
  • deprecating getManifestByDir method
  • removing all cli for blocks
  • removing deprecated renderPartial, getManifest methods.

@iruzevic iruzevic requested a review from a team February 20, 2025 19:43
@iruzevic iruzevic self-assigned this Feb 20, 2025
Copy link
Contributor

@piqusy piqusy left a 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

Copy link
Contributor

@piqusy piqusy left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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',
Copy link
Contributor

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?

Comment on lines -82 to -92
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.
}

Copy link
Contributor

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?

Copy link
Member Author

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

Comment on lines +260 to +293
/**
* 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;
}
Copy link
Contributor

@mbmjertan mbmjertan Feb 21, 2025

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?

Copy link
Member Author

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

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants