Skip to content

Commit

Permalink
make the encoding of the cache key configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ilaoniu committed Dec 6, 2024
1 parent 1c5e80d commit 177f891
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/MobileDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,13 @@ protected function createCacheKey(string $key): string
$userAgentKey = $this->hasUserAgent() ? $this->userAgent : '';
$httpHeadersKey = $this->hasHttpHeaders() ? static::flattenHeaders($this->httpHeaders) : '';

return 'MobileDetect' . md5("$key:$userAgentKey:$httpHeadersKey");
$cacheKey = "$key:$userAgentKey:$httpHeadersKey";

$cacheKeyUsing = $this->config['cacheKeyUsing'] ?? function (string $cacheKey) {
return base64_encode($cacheKey);
};

return call_user_func($cacheKeyUsing, $cacheKey);
}

public static function flattenHeaders(array $httpHeaders): string
Expand Down

0 comments on commit 177f891

Please sign in to comment.