ostark / upper

Integrates Edge Caches like Fastly, KeyCDN, Cloudflare and Varnish with Craft.
MIT License
102 stars 22 forks source link

Excluding query string from cache table #28

Closed petetak closed 5 years ago

petetak commented 5 years ago

Is there a config option or a way to prevent query string parameters from creating a new entry in the upper_cache table please?

My table is getting full of duplicates and therefore takes much longer to clear.

ostark commented 5 years ago

Which "driver" do you use? And what's the behaviour of your edge cache? Do you ignore queries strings there?

petetak commented 5 years ago

We use Cloudflare. On Cloudflare we have a blacklist that we can add certain things to like google utm links or other email software ids

ostark commented 5 years ago

I'm not happy with the Upper 1.x code base (2.x is WIP and consider to integrate it). There is no nice way to do it, but this workaround should work for you:

<?php 

// config/app.php

return [

    'modules'    => [
       // ...
    ],

    'bootstrap' => [
        function () {
            \yii\base\Event::on(
                \ostark\upper\Plugin::class,
                \ostark\upper\Plugin::EVENT_AFTER_SET_TAG_HEADER,
                function (\ostark\upper\events\CacheResponseEvent $event) {
                    // manipulate requestUrl
                    $event->requestUrl = preg_replace( '/&?utm_.+?(&|$)$/', '', $event->requestUrl );
                },
                null,
                false
            );
        }
    ]
];

Please let me know if this works for you.

petetak commented 5 years ago

Thanks!

On 12 Mar 2019, at 20:29, Oliver Stark notifications@github.com wrote:

I'm not happy with the Upper 1.x code base (2.x is WIP and consider to integrate it). There is no nice way to do it, but this workaround should work for you:

<?php

// config/app.php

return [

'modules'    => [
   // ...
],

'bootstrap' => [
    function () {
        \yii\base\Event::on(
            \ostark\upper\Plugin::class,
            \ostark\upper\Plugin::EVENT_AFTER_SET_TAG_HEADER,
            function (\ostark\upper\events\CacheResponseEvent $event) {
                // manipulate requestUrl
                $event->requestUrl = preg_replace( '/&?utm_.+?(&|$)$/', '', $event->requestUrl );
            },
            null,
            false
        );
    }
]

]; — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

ostark commented 5 years ago

@petetak does it work for you?