# cacheIf

abstract fun cacheIf(spec: Spec<in Task>)(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.

#### Since

3.0

#### Parameters

spec

specifies if the results of the task should be cached.

abstract fun cacheIf(cachingEnabledReason: String, spec: Spec<in Task>)(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.

#### Since

3.4

#### Parameters

cachingEnabledReason

the reason why caching would be enabled by the spec.

spec

specifies if the results of the task should be cached.