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

add ignore get params to full request cache #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion src/KeyCreators/ControllerBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Security\Security;
use SilverStripe\View\SSViewer;

class ControllerBased implements KeyCreatorInterface, KeyInformationProviderInterface
{
use Configurable;

/**
* @var array List of GET variables to ignore when generating cache keys
*/
private static $ignored_get_vars = [];

/**
* @var Controller
*/
Expand Down Expand Up @@ -91,7 +99,19 @@ public function getKey($name, $config)
$keyParts[] = md5(Director::absoluteBaseURL($request->getURL()));
break;
case 'full':
$keyParts[] = md5(Director::absoluteBaseURL($request->getURL(true)));
$url = $request->getURL();
$ignoredVars = static::config()->ignored_get_vars;
$vars = $request->getVars();
if (count($ignoredVars)) {
foreach ($ignoredVars as $var) {
unset($vars[$var]);
}
}
if (count($vars)) {
$url .= '?' . http_build_query($vars ?? []);
}

$keyParts[] = md5($url);
break;
}
}
Expand Down