Created
February 16, 2011 10:52
-
-
Save damienalexandre/829183 to your computer and use it in GitHub Desktop.
Fix the 250 chars memcached cache key limit on symfony 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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