How can I retrieve a list of cache keys?

I found that there’s an API endpoint to delete build caches in the documentation. https://circleci.com/docs/api/v1-reference/#clear-cache. The top of the document mentions that it supports both 1.0 and 2.0, however as caches are immutable in 2.0 I suspect that it’s a generic statement and the build cache section needs updating to state that it only applies to 1.0.

My question, however, is how can I retrieve a list of all the cache keys for a specific project? Ideally with when it was created too. Hoping for maybe an undocumented response, a GET request on that same endpoint didn’t return a result. Any other ways to achieve this other than iterating through all build logs looking for the entries where a cache was successfully saved? Which, I don’t even know is possible yet, and would very much be the long way around.

I am not aware of one, I agree it would be a good feature.

As a (ropey) workaround, consider this. Firstly, contact CircleCI and ask them to clear all your caches - I expect that they have to have some way of doing this. Secondly, when you create a key, push it to an external service (e.g. a private BitBucket repo) from where you can retrieve a list of them.

It’s a bit hacky, but it’d work. My experience of all hosted services where there is a missing feature is to try to work around it, rather than to put things on-hold until it is implemented.

Of course, check the ideas list and add your idea as well, if it is not in there.

2 Likes

Done.

https://circleci.ideas.aha.io/ideas/CCI-I-540

1 Like

I just pondered that the Git tagging system could be used for this. Writing a key would be as easy as:

git clone myrepo &&
    git tag -a $CACHE_KEY -m "Here is a cache key" &&
    git push --tags

To get your keys:

git clone myrepo &&
    git tag

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.