Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Adds support for Akamai purging #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Hyra
Copy link

@Hyra Hyra commented May 21, 2021

Rather than writing a custom module I figured Akamai fits well within Upper's drivers.

Let me know what you think.

@ostark
Copy link
Owner

ostark commented May 25, 2021

Thanks @Hyra
I'll have a look

@Hyra
Copy link
Author

Hyra commented Sep 9, 2021

@ostark Anything left to do to get this merged in? ❤️

@ostark
Copy link
Owner

ostark commented Sep 9, 2021

@Hyra A review was missing to get this merged, I guess ...
Sorry, I forgot about this.

Copy link
Owner

@ostark ostark left a comment

Choose a reason for hiding this comment

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

🙈 well, please have a look

@@ -257,14 +256,13 @@ protected static function handleUpdateEvent(Event $event)
Plugin::getInstance()->trigger(Plugin::EVENT_BEFORE_PURGE, $purgeEvent);

// Push to queue
\Craft::$app->getQueue()->push(new PurgeCacheJob([
\Craft::$app->getQueue()->ttr(1200)->push(new PurgeCacheJob(
Copy link
Owner

Choose a reason for hiding this comment

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

Any good reason for ttr(1200)?

Copy link
Author

Choose a reason for hiding this comment

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

In our experience, with sites that have a lot of URLs the purge by url loop takes too long and times out with the default TTR. We actually purge by tag now to avoid this problem, so I guess the ttr might indeed be overkill in most cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Hyra Let's not hardcode this. Either make it a config option, or just remove it and users can control it with EVENT_BEFORE_PUSH.

src/drivers/Akamai.php Show resolved Hide resolved
public function purgeAll()
{
// TODO: Purge all in Akamai
return true;
Copy link
Owner

Choose a reason for hiding this comment

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

is there no endpoint?

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately, no. Only by tag, cp code or url. CP Code could work as a purge all, but only if you set it up specifically.

Copy link
Owner

Choose a reason for hiding this comment

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

I had a quick look at the docs. cp code should work.


$context = stream_context_create($context);

try {
Copy link
Owner

Choose a reason for hiding this comment

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

there is nothing wrong with file_get_contents(), but to be consistent I'd prefer GuzzleHttp\Client

Copy link
Author

Choose a reason for hiding this comment

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

Fair enough, I'll change it ! 👍🏻

Copy link
Collaborator

@timkelty timkelty left a comment

Choose a reason for hiding this comment

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

@Hyra can you add return types to the methods?

@@ -257,14 +256,13 @@ protected static function handleUpdateEvent(Event $event)
Plugin::getInstance()->trigger(Plugin::EVENT_BEFORE_PURGE, $purgeEvent);

// Push to queue
\Craft::$app->getQueue()->push(new PurgeCacheJob([
\Craft::$app->getQueue()->ttr(1200)->push(new PurgeCacheJob(
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Hyra Let's not hardcode this. Either make it a config option, or just remove it and users can control it with EVENT_BEFORE_PUSH.

$_ENV['AKAMAI_CLIENT_SECRET'] = getenv('AKAMAI_CLIENT_SECRET');
$_ENV['AKAMAI_ACCESS_TOKEN'] = getenv('AKAMAI_ACCESS_TOKEN');
$_ENV['AKAMAI_MAX_SIZE'] = getenv('AKAMAI_MAX_SIZE');

Copy link
Collaborator

Choose a reason for hiding this comment

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

These values should be coming from config, not getenv, right?

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

Successfully merging this pull request may close these issues.

3 participants