Problem/Motivation

The code below, clearly works for different languages.

$data = array();
if($cache = cache_get('eu_cookie_compliance_client_settings_' . $language->language, 'cache')) {
  $data = $cache->data;
}
else {
  ... theme-dependent rendering...
}

The problem comes, when there are different themes, that can define different templates for the pop-up. Themes can be switched in many ways:
- Per domain with some domain_access sub-module.
- Per site-builder's condition with themekey module.
- Others...

The end result is that the popup is rendered in one theme, but it's markup can be displayed in another from cache, causing UI breakages.

Proposed resolution

I can think of 2 options for fixing this (non mutually exclusive):
1. Harder - Expose a hook/API to manipulate the used cache key.
2. Add the currently active theme to the key's generation.

Any other ideas?

Remaining tasks

Patch, review, rtbc, commit.

User interface changes

None.

API changes

Addition / None - depending on the solution that is taken.

Data model changes

None.

Comments

ndobromirov created an issue. See original summary.

ndobromirov’s picture

Title: Rendered output is not cached correctly. » Cache key is too generic
Status: Active » Needs review
StatusFileSize
new2.71 KB

Updated title to reflect the issue more correctly.
Here is a patch that implements option 2 + some re-formatting.

svenryen’s picture

Assigned: Unassigned » svenryen

Thank you for the patch. I will have a look and commit if it passes testing.

ndobromirov’s picture

Something that I have missed initially, as it was part of the original code, so it's maybe a separate issue...

  cache_set($cid, $data, 'cache', CACHE_TEMPORARY);

1. Is this Really needed to be temporary?
2. Can we set it to something more greedy (hour / day / CACHE_PERMANENT / custom TTL config)?

The rendered values in the pop-up fully depend on the config form (in terms of content), so on re-save it will clear it either way. As it is at the moment I do not see reason for the TEMPORARY vs PERMANENT or at least some cache TTL.

BR, Nick.

dakku’s picture

option 2 seems ok to me. Thank for the patch

svenryen’s picture

Status: Needs review » Needs work

@ndobromirov, thanks you again for the patch. I tried applying it and it doesn't apply to the latest beta release. Do you think you could re-roll it, and I'll take a look an review it?

ndobromirov’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
Issue tags: +Performance, +scalability
StatusFileSize
new2.6 KB

As you can see this issue was against 7.x-2.x version of the module. There were no commits there for the last ~2 years. What's the status for it?

Re-rolling the patch against version 1. Changes include:
1. Fix of the cache key name-spacing.
2. More consistent cache clear, as the existing one was clearly wrong / not working.
3. As per the discussion in #4 and #5 changed the cache TTL from temporary to permanent.

BR, Nick.

svenryen’s picture

@ndobromirov/Nick, we don't plan to use the 2.x version unless we introduce something that breaks backwards compatibility.

In the 1.x code base we already had the key eu_cookie_compliance_client_settings_' . $theme . '_' . $language->language, what are your benefits of changing this to eu_cookie_compliance_client_settings:' . $language->language . ':' . $theme?

Also, how do I test that your code actually works as intended. I'm able to verify it has no side-effects, but what should I expect to see when I set up a site that has two themes available?

  • svenryen committed 47d4307 on 7.x-1.x
    Issue #2705743 by ndobromirov: Cache key is  too generic
    
ndobromirov’s picture

Status: Needs review » Fixed

The issue was in the cache clear scenario - the key was prefix:thme:lang when setting, but it was removing single key in the prefix:lang convention. This way the cache will never be cleared, unless you wipe the whole thing out.

If both themes are active at the same time (based on a rule or something), rendered stuff from one should not show on the other.
This was fixed, as I only changed the cache clear on a config change part and the cache TTL.

Apparently the issue in 2.x was not present (that much) in 1.x, or this was duplicated.
I am marking this as fixed.

svenryen’s picture

Thanks for marking it as fixed. I won't pull out your code, so it will be in the next release.

ndobromirov’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.