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 key id prefix #3384

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/recipe/magento2.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,25 @@ Upgrades magento database.



### magento:set_cache_prefix
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L198)

Update cache id_prefix.

Update cache ip_prefix on deploy so that your are compiling against a fresh cache
Reference Issue: https://github.com/davidalger/capistrano-magento2/issues/151


### magento:cache:flush
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L194)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L225)

Flushes Magento Cache.




### deploy:magento
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L199)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L230)

Magento2 deployment operations.

Expand All @@ -296,7 +305,7 @@ This task is group task which contains next tasks:


### magento:build
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L207)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L238)

Magento2 build operations.

Expand All @@ -309,7 +318,7 @@ This task is group task which contains next tasks:


### deploy
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L213)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L244)

Deploys your project.

Expand Down
31 changes: 31 additions & 0 deletions recipe/magento2.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,37 @@
}
});

/**
* Update cache ip_prefix on deploy so that your are compiling against a fresh cache
* Reference Issue: https://github.com/davidalger/capistrano-magento2/issues/151
**/
desc('Update cache id_prefix');
task('magento:set_cache_prefix', function () {
//check and only run if env.php is a symlink
if (test('[ -L {{release_or_current_path}}/app/etc/env.php ]')) {
//get local temp file name
$tmpFilename = tempnam(sys_get_temp_dir(), 'tmp_settings_');
//download env.php to local temp file
download("{{deploy_path}}/shared/app/etc/env.php", $tmpFilename, ['progress_bar' => false]);
$envConfig = include($tmpFilename);
$prefixUpdate = get('release_name') . '_';
//update id_prefix to include release name
$envConfig["cache"]["frontend"]["default"]["id_prefix"] = $envConfig["cache"]["frontend"]["default"]["id_prefix"] . $prefixUpdate;
$envConfig["cache"]["frontend"]["page_cache"]["id_prefix"] = $envConfig["cache"]["frontend"]["page_cache"]["id_prefix"] . $prefixUpdate;

//create temporary config file locally
$envConfigStr = "<?php return " . var_export($envConfig, true) . ";";
file_put_contents($tmpFilename, $envConfigStr);
//delete the remote symlink for env.php
run("rm {{release_or_current_path}}/app/etc/env.php");
//upload to server
upload($tmpFilename, '{{release_or_current_path}}/app/etc/env.php', ['progress_bar' => false]);
//delete local temp file
unlink($tmpFilename);
}
});
after('deploy:shared', 'magento:set_cache_prefix');

desc('Flushes Magento Cache');
task('magento:cache:flush', function () {
run("{{bin/php}} {{release_or_current_path}}/bin/magento cache:flush");
Expand Down