Skip to content

Instantly share code, notes, and snippets.

@damienalexandre
Created February 16, 2011 10:52
Show Gist options
  • Save damienalexandre/829183 to your computer and use it in GitHub Desktop.
Save damienalexandre/829183 to your computer and use it in GitHub Desktop.
Fix the 250 chars memcached cache key limit on symfony 1
<?php
/**
* Set cache_namespace_callable: [ pouet, generateShortenedCacheKey ] in your settings.yml
* Then the symfony cache key is shortened by MD5
*
* @author dalexandre
* @see sfViewCacheManager::generateCacheKey
* @param sfViewCacheManager $sfViewCacheManager
* @return string
*/
public static function generateShortenedCacheKey($internalUri, $hostName, $vary, $contextualPrefix, $sfViewCacheManager)
{
// Store and destroy the callable param, because we want to use the internal generated key.
$sfconfig = sfConfig::get('sf_cache_namespace_callable');
sfConfig::set('sf_cache_namespace_callable', false);
$key = md5($sfViewCacheManager->generateCacheKey($internalUri, $hostName, $vary, $contextualPrefix));
// Restaure the initial config and return the short key
sfConfig::set('sf_cache_namespace_callable', $sfconfig);
return $key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment