# CacheKeyFactory

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/datasource/cache/CacheKeyFactory "View this page in Java")

<br />

```
@UnstableApi
interface CacheKeyFactory
```

<br />

*** ** * ** ***

Factory for cache keys.

## Summary

|                                                         ### Constants                                                         |
|-------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[CacheKeyFactory](https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheKeyFactory)`!` | [DEFAULT](https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheKeyFactory#DEFAULT()) Default[CacheKeyFactory](https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheKeyFactory). |

|                                 ### Public functions                                 |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [buildCacheKey](https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheKeyFactory#buildCacheKey(androidx.media3.datasource.DataSpec))`(dataSpec: `[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec)`!)` Returns the cache key of the resource containing the data defined by a[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec). |

## Constants

### DEFAULT

```
const val DEFAULT: CacheKeyFactory!
```

Default[CacheKeyFactory](https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/CacheKeyFactory).  

## Public functions

### buildCacheKey

```
fun buildCacheKey(dataSpec: DataSpec!): String!
```

Returns the cache key of the resource containing the data defined by a[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec).

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

|                                                  Parameters                                                   |
|---------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| `dataSpec: `[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec)`!` | The[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec). |

|                                       Returns                                        |
|--------------------------------------------------------------------------------------|--------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The cache key of the resource. |