How can I use actions/cache except some directory?

I use actions/cache to cache docker-compose images, example:

cache-docker-images-${{ hashFiles('api') }}

and there is a “test” directory under the “api” directory. Now, I don’t want to hash the test directory, that is, I want to hash all the files in the api directory except the test directory, is there any solution?