gradle
8.6

# cacheIf

abstract fun cacheIf(spec: Spec<out Any>)(source)

Cache the results of the task only if the given spec is satisfied. If the spec is not satisfied, the results of the task will not be cached.

You may add multiple such predicates. The results of the task are not cached if any of the predicates return `false`, or if any of the predicates passed to doNotCacheIf returns `true`. If `cacheIf()` is not specified, the task will not be cached unless the @CacheableTask annotation is present on the task type.

Consider using cacheIf instead for also providing a reason for enabling caching.

#### Parameters

spec

specifies if the results of the task should be cached.

abstract fun cacheIf(cachingEnabledReason: String, spec: Spec<out Any>)(source)

Cache the results of the task only if the given spec is satisfied. If the spec is not satisfied, the results of the task will not be cached.

You may add multiple such predicates. The results of the task are not cached if any of the predicates return `false`, or if any of the predicates passed to doNotCacheIf returns `true`. If `cacheIf()` is not specified, the task will not be cached unless the @CacheableTask annotation is present on the task type.

#### Parameters

cachingEnabledReason

the reason why caching would be enabled by the spec.

spec

specifies if the results of the task should be cached.