Quick docs question about this page: http://www.php-cache.com/en/latest/introduction/
The suggested hash method is $cacheKey = sha1($_SERVER['REQUEST_URI']);
But my understanding is that sha1 is intentionally an expensive hashing operation compared to md5. Is there a reason not to recommend using md5 for hashing cache keys?
@james_beninger_twitter I don't know about md5 vs sha1, but I've been using a custom method with success. It has the advantage to accept anything as input, including objects:
/**
* Returns a unique key identifying all arguments in the array, so we can use the result as cache key
*
* This only works for in-memory objects. The key returned should *never* be
* persisted. And it may be expensive in memory because object are forced
* not to be garbage collected.
*
* @param mixed $value
*
* @return string
*/
public static function getCacheKey($value): string
{
static $preventGarbageCollectorFromDestroyingObject = [];
if (is_object($value)) {
$preventGarbageCollectorFromDestroyingObject[] = $value;
return spl_object_hash($value);
}
if (is_array($value)) {
$key = '[ARRAY|';
foreach ($value as $i => $modelInCollection) {
$key .= $i . '>' . self::getCacheKey($modelInCollection) . ':';
}
return $key . ']';
}
if (is_bool($value)) {
return '[BOOL|' . $value . ']';
}
if ($value === null) {
return '[NULL]';
}
return (string) $value;
}
Common usages could be something like:
function doSomethingExpansive($currentUser, $foo)
{
$key = Cache::getCacheKey(func_get_args());
$keyWithExtrasStuff = Cache::getCacheKey([
$currentUser,
$foo,
$bar,
]);
// ...
}
Cell entry AF649 no longer exists in cache. This probably means that the cache was cleared by someone else.
<IfModule mod_headers.c>
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|ttf|otf|eot|woff|woff2)$">
Header set Cache-Control "public, max-age=30"
</filesMatch>
</IfModule>