Hi there, we are using this module on our website that has some long paths that require different metatag titles/content.

I've noticed that the function metatag_cache_default_cid_parts() can generate the same cache key for different paths, which we are finding is causing incorrect metatags to be generated for some pages:

Eg. for the page:

http://www.visitnsw.com/destinations/snowy-mountains/kosciuszko-national...

metatag_cache_default_cid_parts returns "output:global:en:200:http:www.visitnsw.com:/:destinations/snowy-mountains/kosciuszko-national..."

And for

http://www.visitnsw.com/destinations/snowy-mountains/kosciuszko-national...

metatag_cache_default_cid_parts also returns "output:global:en:200:http:www.visitnsw.com:/:destinations/snowy-mountains/kosciuszko-national..."

It's this conflict that's causing them to "share" the metatag data, whichever page gets hit first gets the correct data cached, but any other pages that share this cache key use the incorrect data.

Is there a way around this? Is there a reason the return value of metatag_cache_default_cid_parts cannot just be a MD5 or SHA1 hash generated from the string before it is truncated?

Am happy to roll a patch for this tomorrow, but just wanted to log this as an issue.

Comments

thomwilhelm’s picture

Adding patch of proposed solution.

thomwilhelm’s picture

Issue summary: View changes
thomwilhelm’s picture

Actually on inspection of the database table cache_metatag could this value instead be trimmed to 255 chars rather than 128 chars?

damienmckenna’s picture

Status: Active » Needs work

Could you please take a look at #2474427: Drop the output cache and let me know if it's an acceptable temporary solution?

damienmckenna’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new532 bytes

Does this help? It changes the truncated cache $cid to 255 chars instead of 128.

damienmckenna’s picture

Status: Needs review » Fixed

I committed the small string truncation patch.

  • DamienMcKenna committed 370d50e on 7.x-1.x
    Issue #2487179 by DamienMcKenna: Allow longer cache IDs to reduce...
thomwilhelm’s picture

Yep no worries I'll test out your changes hopefully later this week. Thanks for your help.

thomwilhelm’s picture

Hi again Damien. Yes, both patches fix the issue for entities.

However the pages that generate the long URL's in our application are not Drupal entities, it's a custom module that wildcard matches anything in the URL after "/destinations/" and then does some processing to return the correct content from an external database (it's a wonderful system... not). I hope I've explained that clearly :)

Anyway changing the limit to 255 is fine for our case, it's a bit of a unusual case I know...

I was wondering if a better solution that handles all cases could be just check inside metatag_cache_get() if 'metatag_cache_output" is TRUE, and if it's not then just return NULL. I might experiment with this further myself.

Status: Fixed » Closed (fixed)

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