How to get the corresponding taskName with a build cachekey

Hi, are there any good practices to get the taskName by a cacheKey?

any API I can use?

There’s no way to do this, for two main reasons:

  1. A cache key is effectively a hash, meaning from the inputs I can reproduce the same hash, but you can’t infer the inputs from the hash. It’s a one way algorithm.
  2. Even if you could deduce the cache inputs from the hash, you wouldn’t in this case because task name is not part of the hash. That is, two tasks with different names, for otherwise the same inputs, can produce the same cache key.

Thanks for the quick reply.

I know that it’s no way to infer the inputs from the hash. What I’d like to do is collecting cache keys to figure out which tasks are easily cache-miss in our project through different engineer’s environment. Right now, I can only receive the cache keys from my own cache server without any taskName information.

It’s totally fine for me to collect this information in the runtime environment.

Right, because cache requests don’t include the task name. When Gradle asks the build cache for a task’s output the request is simply the key itself, no information about the task is in the GET request.

That said, the cached task outputs do contain a metadata file with origin task information, but this won’t help you in the case of cache misses, because in that scenario there is no cache artifact on the server, hence the miss.

It’s totally fine for me to collect this information in the runtime environment.

Build scans already collect this information so you might look into using Gradle Enterprise for this purpose.