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

Shortcode are not being cached #597

Closed
2 tasks done
maxime-rainville opened this issue Apr 29, 2024 · 3 comments
Closed
2 tasks done

Shortcode are not being cached #597

maxime-rainville opened this issue Apr 29, 2024 · 3 comments

Comments

@maxime-rainville
Copy link
Contributor

maxime-rainville commented Apr 29, 2024

Module version(s) affected

2.2.0, but probably all version of 2

Description

The method that's meant to check the cache for FileShortcodeProvider and ImageShortcodeProvider will always return an empty string unless you allow session grant.

In CMS4, I think session grant was enabled by default so this wasn't a problem.

protected static function getCachedMarkup($cache, $cacheKey, $arguments): string
{
$item = $cache->get($cacheKey);
$assetStore = Injector::inst()->get(AssetStore::class);
if ($item && $item['markup'] && !empty($item['filename'])) {
// Initiate a protected asset grant if necessary
$allowSessionGrant = static::getGrant(null, $arguments);
if ($allowSessionGrant && $assetStore->exists($item['filename'], $item['hash'])) {
$assetStore->grant($item['filename'], $item['hash']);
return $item['markup'];
}
}
return '';
}

How to reproduce

  • Add a die('cache hit'); statement in this if clause
    $cache = static::getCache();
    $cacheKey = static::getCacheKey($args, $content);
    $cachedMarkup = static::getCachedMarkup($cache, $cacheKey, $args);
    if ($cachedMarkup) {
    return $cachedMarkup;
    }
    .
  • Add an Image to a WYSIWYG and publish the page.
  • Access the page twice.

Expected results: I hit the die statement.
Actual: My cache check always returns a blank string and I regenerate the short code each time.

Possible Solution

No response

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)

Pull request

@GuySartorelli
Copy link
Member

GuySartorelli commented Apr 29, 2024

@maxime-rainville Please link to any revelant PRs since this is in the peer review column

@maxime-rainville
Copy link
Contributor Author

Added a link to PR #598

@GuySartorelli
Copy link
Member

PR merged. Will be automatically tagged by GitHub actions

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

No branches or pull requests

2 participants