# CacheSpan

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

*** ** * ** ***


```
@UnstableApi
public class CacheSpan implements Comparable<CacheSpan>
```

<br />

*** ** * ** ***

Defines a span of data that may or may not be cached (as indicated by `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()`).

## Summary

| ### Public fields |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#file()` The file corresponding to this `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or null if `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()` is false. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()` Whether the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan` is cached. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#key()` The cache key that uniquely identifies the resource. |
| `final long` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#lastTouchTimestamp()` The last touch timestamp, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()` is false. |
| `final long` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#length()` The length of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if this is an open-ended hole. |
| `final long` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#position()` The position of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan` in the resource. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#CacheSpan(java.lang.String,long,long)(https://developer.android.com/reference/java/lang/String.html key, long position, long length)` Creates a hole CacheSpan which isn't cached, has no last touch timestamp and no file associated. |
| `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#CacheSpan(java.lang.String,long,long,long,java.io.File)( https://developer.android.com/reference/java/lang/String.html key, long position, long length, long lastTouchTimestamp, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/io/File.html file )` Creates a CacheSpan. |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#compareTo(androidx.media3.datasource.cache.CacheSpan)(https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan another)` |
| `boolean` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isHoleSpan()()` Returns whether this is a hole `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isOpenEnded()()` Returns whether this is an open-ended `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#toString()()` |

## Public fields

### file

```
public final @Nullable File file
```

The file corresponding to this `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or null if `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()` is false.

### isCached

```
public final boolean isCached
```

Whether the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan` is cached.

### key

```
public final String key
```

The cache key that uniquely identifies the resource.

### lastTouchTimestamp

```
public final long lastTouchTimestamp
```

The last touch timestamp, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()` is false.

### length

```
public final long length
```

The length of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if this is an open-ended hole.

### position

```
public final long position
```

The position of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan` in the resource.

## Public constructors

### CacheSpan

```
public CacheSpan(String key, long position, long length)
```

Creates a hole CacheSpan which isn't cached, has no last touch timestamp and no file associated.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html key` | The cache key that uniquely identifies the resource. |
| `long position` | The position of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan` in the resource. |
| `long length` | The length of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if this is an open-ended hole. |

### CacheSpan

```
public CacheSpan(
    String key,
    long position,
    long length,
    long lastTouchTimestamp,
    @Nullable File file
)
```

Creates a CacheSpan.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html key` | The cache key that uniquely identifies the resource. |
| `long position` | The position of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan` in the resource. |
| `long length` | The length of the `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if this is an open-ended hole. |
| `long lastTouchTimestamp` | The last touch timestamp, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan#isCached()` is false. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/io/File.html file` | The file corresponding to this `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`, or null if it's a hole. |

## Public methods

### compareTo

```
public int compareTo(CacheSpan another)
```

### isHoleSpan

```
public boolean isHoleSpan()
```

Returns whether this is a hole `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`.

### isOpenEnded

```
public boolean isOpenEnded()
```

Returns whether this is an open-ended `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheSpan`.

### toString

```
public String toString()
```