Skip to content

How to change the Prefix of the cache key? #480

Closed Answered by khangphung-vl
khangphung-vl asked this question in Q&A
Discussion options

You must be logged in to vote

Answer

It's not possible due to the "responsecache" string is built-in the Default Hasher, inside the getHashFor function. One way to work around this is write your own Hasher that extends DefaultHasher, re-implement getHashFor function to achieve the desired return string.

public function getHashFor(Request $request): string
{
    $cacheNameSuffix = $this->getCacheNameSuffix($request);

    return 'responsecache-' . hash(
        'xxh128',
        "{$request->getHost()}-{$this->getNormalizedRequestUri($request)}-{$request->getMethod()}/$cacheNameSuffix"
    );
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by khangphung-vl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant