Package com.google.android.exoplayer2.upstream

## Class CachedRegionTracker

- java.lang.Object
- - com.google.android.exoplayer2.upstream.CachedRegionTracker

- All Implemented Interfaces:
    `Cache.Listener`

      public final class CachedRegionTracker
      extends Object
      implements Cache.Listener

  Utility class for efficiently tracking regions of data that are stored in a `Cache` for a given cache key.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `CACHED_TO_END` |
    `static int` | `NOT_CACHED` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CachedRegionTracker​(Cache cache, String cacheKey, ChunkIndex chunkIndex)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `getRegionEndTimeMs​(long byteOffset)` | When provided with a byte offset, this method locates the cached region within which the offset falls, and returns the approximate end position in milliseconds of that region.
    `void` | `onSpanAdded​(Cache cache, CacheSpan span)` | Called when a `CacheSpan` is added to the cache.
    `void` | `onSpanRemoved​(Cache cache, CacheSpan span)` | Called when a `CacheSpan` is removed from the cache.
    `void` | `onSpanTouched​(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)` | Called when an existing `CacheSpan` is touched, causing it to be replaced.
    `void` | `release()` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NOT_CACHED

          public static final int NOT_CACHED

      See Also:
        Constant Field Values

    - #### CACHED_TO_END

          public static final int CACHED_TO_END

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CachedRegionTracker

          public CachedRegionTracker​(Cache cache,
                                     String cacheKey,
                                     ChunkIndex chunkIndex)

  - ### Method Detail

    - #### release

          public void release()

    - #### getRegionEndTimeMs

          public int getRegionEndTimeMs​(long byteOffset)

      When provided with a byte offset, this method locates the cached region within which the offset falls, and returns the approximate end position in milliseconds of that region. If the byte offset does not fall within a cached region then `NOT_CACHED` is returned. If the cached region extends to the end of the stream, `CACHED_TO_END` is returned.
      Parameters:
        `byteOffset` - The byte offset in the underlying stream.
      Returns:
        The end position of the corresponding cache region, `NOT_CACHED`, or `CACHED_TO_END`.

    - #### onSpanAdded

          public void onSpanAdded​(Cache cache,
                                  CacheSpan span)

      Description copied from interface: `Cache.Listener`
      Called when a `CacheSpan` is added to the cache.
      Specified by:
        `onSpanAdded` in interface `Cache.Listener`
      Parameters:
        `cache` - The source of the event.
        `span` - The added `CacheSpan`.

    - #### onSpanRemoved

          public void onSpanRemoved​(Cache cache,
                                    CacheSpan span)

      Description copied from interface: `Cache.Listener`
      Called when a `CacheSpan` is removed from the cache.
      Specified by:
        `onSpanRemoved` in interface `Cache.Listener`
      Parameters:
        `cache` - The source of the event.
        `span` - The removed `CacheSpan`.

    - #### onSpanTouched

          public void onSpanTouched​(Cache cache,
                                    CacheSpan oldSpan,
                                    CacheSpan newSpan)

      Description copied from interface: `Cache.Listener`
      Called when an existing `CacheSpan` is touched, causing it to be replaced. The new `CacheSpan` is guaranteed to represent the same data as the one it replaces, however `CacheSpan.file` and `CacheSpan.lastTouchTimestamp` may have changed.

      Note that for span replacement, `Cache.Listener.onSpanAdded(Cache, CacheSpan)` and `Cache.Listener.onSpanRemoved(Cache, CacheSpan)` are not called in addition to this method.

      Specified by:
        `onSpanTouched` in interface `Cache.Listener`
      Parameters:
        `cache` - The source of the event.
        `oldSpan` - The old `CacheSpan`, which has been removed from the cache.
        `newSpan` - The new `CacheSpan`, which has been added to the cache.