# CacheKeyFactory

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/CacheKeyFactory.java+class:androidx.media3.datasource.cache.CacheKeyFactory)

*** ** * ** ***


```
@UnstableApi
public interface CacheKeyFactory
```

<br />

*** ** * ** ***

Factory for cache keys.

## Summary

| ### Constants |
|---|---|
| `default static final https://developer.android.com/reference/androidx/media3/datasource/cache/CacheKeyFactory` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheKeyFactory#DEFAULT()` Default `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheKeyFactory`. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheKeyFactory#buildCacheKey(androidx.media3.datasource.DataSpec)(https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec)` Returns the cache key of the resource containing the data defined by a `https://developer.android.com/reference/androidx/media3/datasource/DataSpec`. |

## Constants

### DEFAULT

```
default static final CacheKeyFactory DEFAULT
```

Default `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheKeyFactory`.

## Public methods

### buildCacheKey

```
abstract String buildCacheKey(DataSpec dataSpec)
```

Returns the cache key of the resource containing the data defined by a `https://developer.android.com/reference/androidx/media3/datasource/DataSpec`.

Note that since the returned cache key corresponds to the whole resource, implementations must not return different cache keys for `https://developer.android.com/reference/androidx/media3/datasource/DataSpec` that define different ranges of the same resource. As a result, implementations should not use fields such as `https://developer.android.com/reference/androidx/media3/datasource/DataSpec#position()` and `https://developer.android.com/reference/androidx/media3/datasource/DataSpec#length()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSpec`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The cache key of the resource. |