# CacheDataSink.Factory

Artifact: [androidx.media3:media3-datasource](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/datasource/cache/CacheDataSink.java+class:androidx.media3.datasource.cache.CacheDataSink.Factory)

*** ** * ** ***


```
class CacheDataSink.Factory : DataSink.Factory
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink.Factory` for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink` instances.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory#Factory()()` Creates an instance. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink!` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory#createDataSink()()` Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink` instance. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory#setBufferSize(int)(bufferSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the size of an in-memory buffer used when writing to a cache file. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory#setCache(androidx.media3.datasource.cache.Cache)(cache: https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache!)` Sets the cache to which data will be written. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory#setFragmentSize(long)(fragmentSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the cache file fragment size. |

## Public constructors

### Factory

```
Factory()
```

Creates an instance.

## Public functions

### createDataSink

```
fun createDataSink(): DataSink!
```

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSink` instance.

### setBufferSize

```
@CanIgnoreReturnValue
fun setBufferSize(bufferSize: Int): CacheDataSink.Factory!
```

Sets the size of an in-memory buffer used when writing to a cache file. A zero or negative value disables buffering.

The default value is `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink#DEFAULT_BUFFER_SIZE()`.

| Parameters |
|---|---|
| `bufferSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The buffer size in bytes. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory!` | This factory. |

### setCache

```
@CanIgnoreReturnValue
fun setCache(cache: Cache!): CacheDataSink.Factory!
```

Sets the cache to which data will be written.

Must be called before the factory is used.

| Parameters |
|---|---|
| `cache: https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache!` | The cache to which data will be written. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory!` | This factory. |

### setFragmentSize

```
@CanIgnoreReturnValue
fun setFragmentSize(fragmentSize: Long): CacheDataSink.Factory!
```

Sets the cache file fragment size. For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set to `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` then no fragmentation will occur. Using a small value allows for finer-grained cache eviction policies, at the cost of increased overhead both on the cache implementation and the file system. Values under `(2 * 1024 * 1024)` are not recommended.

The default value is `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink#DEFAULT_FRAGMENT_SIZE()`.

| Parameters |
|---|---|
| `fragmentSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The fragment size in bytes, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` to disable fragmentation. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheDataSink.Factory!` | This factory. |