api / org.gradle.api.tasks / TaskOutputs / cacheIf

cacheIf

abstract fun cacheIf(spec: Spec<in Task>): Unit

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(String, Spec) 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(String, Spec) instead for also providing a reason for disabling caching.

Parameters

spec - specifies if the results of the task should be cached.

Since
3.0

abstract fun cacheIf(cachingEnabledReason: String, spec: Spec<in Task>): Unit

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(String, Spec) 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.

Since
3.4