Invalidate cache of Nexus group repository via Groovy

Hello Community,

Is there any preferred method to invalidate cache via a Groovy script which can be executed by Nexus task executor?

Following the groovy scripting guide provided at (GitHub - sonatype-nexus-community/nexus-scripting-examples: Sample scripts that use NXRM's scripting interface).

I think the Repository API for scripts (REST and Integration API) only allows to view the content/create new repositories via Groovy. Could this API be somehow extended to invalidate group repository cache via Groovy?

Would manually creating an Object of RepositoryCacheInvalidationService class in Groovy (nexus-public/RepositoryCacheInvalidationService.java at main · sonatype/nexus-public · GitHub) to call cache invalidation function work? Or could there be a better way to handle it via Groovy?

As of now I could only found a way to do it via a cURL POST request <nexus-url/service/rest/v1/repositories/npm-group/invalidate-cache> .

Many thanks in advance for your support.

Cheers