How to get Drupal cache key? If you have caching enabled in Drupal, instead of getting URLs like so:

image.png


You get:

image.png?itok=RANDOMNESS


What function would I need to call to get back the value = "RANDOMNESS"? I ask, because I want to cache other things using the same method Drupal does internally.

Any ideas?
The itok is defined in ImageStyle@getPathToken entity when building the URL (ImageStyle@buildUrl):

  /**
   * {@inheritdoc}
   */
  public function getPathToken($uri) {
    // Return the first 8 characters.
    return substr(Crypt::hmacBase64($this-&gt;id() . ':' . $this-&gt;addExtension($uri), $this-&gt;getPrivateKey() . $this-&gt;getHashSalt()), 0, 8);
  }