CacheDataSource.Factory
public final class CacheDataSource.Factory implements DataSource.Factory
DataSource.Factory for CacheDataSource instances.
Summary
Public fields |
|
|---|---|
@MonotonicNonNull Cache |
|
CacheKeyFactory |
|
@Nullable PriorityTaskManager |
Public constructors |
|---|
Factory() |
Public fields
Public constructors
Public methods
createDataSourceForDownloading
public CacheDataSource createDataSourceForDownloading()
Returns an instance suitable for downloading content. The created instance is equivalent to one that would be created by createDataSource, except:
- The
FLAG_BLOCK_ON_CACHEis always set. - The task priority is overridden to be
PRIORITY_DOWNLOAD.
| Returns | |
|---|---|
CacheDataSource |
An instance suitable for downloading content. |
createDataSourceForRemovingDownload
public CacheDataSource createDataSourceForRemovingDownload()
Returns an instance suitable for reading cached content as part of removing a download. The created instance is equivalent to one that would be created by createDataSource, except:
- The upstream is overridden to be
null, since when removing content we don't want to request anything that's not already cached. - The
FLAG_BLOCK_ON_CACHEis always set. - The task priority is overridden to be
PRIORITY_DOWNLOAD.
| Returns | |
|---|---|
CacheDataSource |
An instance suitable for reading cached content as part of removing a download. |
getCache
public @Nullable Cache getCache()
Returns the cache that will be used, or null if setCache has yet to be called.
getCacheKeyFactory
public CacheKeyFactory getCacheKeyFactory()
Returns the CacheKeyFactory that will be used.
getUpstreamPriorityTaskManager
public @Nullable PriorityTaskManager getUpstreamPriorityTaskManager()
Returns the PriorityTaskManager that will bs used when requesting data from upstream, or null if there is none.
setCache
@CanIgnoreReturnValue
public CacheDataSource.Factory setCache(Cache cache)
Sets the cache that will be used.
Must be called before the factory is used.
| Parameters | |
|---|---|
Cache cache |
The cache that will be used. |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setCacheKeyFactory
@CanIgnoreReturnValue
public CacheDataSource.Factory setCacheKeyFactory(CacheKeyFactory cacheKeyFactory)
Sets the CacheKeyFactory.
The default is DEFAULT.
| Parameters | |
|---|---|
CacheKeyFactory cacheKeyFactory |
The |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setCacheReadDataSourceFactory
@CanIgnoreReturnValue
public CacheDataSource.Factory setCacheReadDataSourceFactory(
DataSource.Factory cacheReadDataSourceFactory
)
Sets the DataSource.Factory for DataSources for reading from the cache.
The default is a FileDataSource.Factory in its default configuration.
| Parameters | |
|---|---|
DataSource.Factory cacheReadDataSourceFactory |
The |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setCacheWriteDataSinkFactory
@CanIgnoreReturnValue
public CacheDataSource.Factory setCacheWriteDataSinkFactory(
@Nullable DataSink.Factory cacheWriteDataSinkFactory
)
Sets the DataSink.Factory for generating DataSinks for writing data to the cache. Passing null causes the cache to be read-only.
The default is a CacheDataSink.Factory in its default configuration.
| Parameters | |
|---|---|
@Nullable DataSink.Factory cacheWriteDataSinkFactory |
The |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setEventListener
@CanIgnoreReturnValue
public CacheDataSource.Factory setEventListener(@Nullable CacheDataSource.EventListener eventListener)
Sets the {link EventListener} to which events are delivered.
The default is null.
| Parameters | |
|---|---|
@Nullable CacheDataSource.EventListener eventListener |
The |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setFlags
@CanIgnoreReturnValue
public CacheDataSource.Factory setFlags(@CacheDataSource.Flags int flags)
Sets the CacheDataSource.Flags.
The default is 0.
| Parameters | |
|---|---|
@CacheDataSource.Flags int flags |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setUpstreamDataSourceFactory
@CanIgnoreReturnValue
public CacheDataSource.Factory setUpstreamDataSourceFactory(
@Nullable DataSource.Factory upstreamDataSourceFactory
)
Sets the DataSource.Factory for upstream DataSources, which are used to read data in the case of a cache miss.
The default is null, and so this method must be called before the factory is used in order for data to be read from upstream in the case of a cache miss.
| Parameters | |
|---|---|
@Nullable DataSource.Factory upstreamDataSourceFactory |
The upstream |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setUpstreamPriority
@CanIgnoreReturnValue
public CacheDataSource.Factory setUpstreamPriority(@C.Priority int upstreamPriority)
Sets the C.Priority to use when requesting data from upstream. The priority is only used if a PriorityTaskManager is set by calling setUpstreamPriorityTaskManager.
The default is PRIORITY_PLAYBACK.
| Parameters | |
|---|---|
@C.Priority int upstreamPriority |
The |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |
setUpstreamPriorityTaskManager
@CanIgnoreReturnValue
public CacheDataSource.Factory setUpstreamPriorityTaskManager(
@Nullable PriorityTaskManager upstreamPriorityTaskManager
)
Sets an optional PriorityTaskManager to use when requesting data from upstream.
If set, reads from the upstream DataSource will only be allowed to proceed if there are no higher priority tasks registered to the PriorityTaskManager. If there exists a higher priority task then PriorityTaskManager.PriorityTooLowException will be thrown instead.
Note that requests to CacheDataSource instances are intended to be used as parts of (possibly larger) tasks that are registered with the PriorityTaskManager, and hence CacheDataSource does not register a task by itself. This must be done by the surrounding code that uses the CacheDataSource instances.
The default is null.
| Parameters | |
|---|---|
@Nullable PriorityTaskManager upstreamPriorityTaskManager |
The upstream |
| Returns | |
|---|---|
CacheDataSource.Factory |
This factory. |