CacheWriter
@UnstableApi
class CacheWriter
Caching related utility methods.
Summary
Nested types |
|---|
interface CacheWriter.ProgressListenerReceives progress updates during cache operations. |
Constants |
|
|---|---|
const Int |
DEFAULT_BUFFER_SIZE_BYTES = 131072Default buffer size to be used while caching. |
Public constructors |
|---|
CacheWriter( |
Public functions |
|
|---|---|
Unit |
Caches the requested data, skipping any that's already cached. |
Unit |
cancel()Cancels this writer's caching operation. |
Constants
DEFAULT_BUFFER_SIZE_BYTES
const val DEFAULT_BUFFER_SIZE_BYTES = 131072: Int
Default buffer size to be used while caching.
Public constructors
CacheWriter
CacheWriter(
dataSource: CacheDataSource!,
dataSpec: DataSpec!,
temporaryBuffer: ByteArray?,
progressListener: CacheWriter.ProgressListener?
)
| Parameters | |
|---|---|
dataSource: CacheDataSource! |
A |
dataSpec: DataSpec! |
Defines the data to be written. |
temporaryBuffer: ByteArray? |
A temporary buffer to be used during caching, or |
progressListener: CacheWriter.ProgressListener? |
An optional progress listener. |
Public functions
cache
@WorkerThread
fun cache(): Unit
Caches the requested data, skipping any that's already cached.
If the CacheDataSource used by the writer has a PriorityTaskManager, then it's the responsibility of the caller to call add to register with the manager before calling this method, and to call remove afterwards to unregister. PriorityTooLowException will be thrown if the priority required by the CacheDataSource is not high enough for progress to be made.
This method may be slow and shouldn't normally be called on the main thread.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs reading the data, or writing the data into the cache, or if the operation is canceled. If canceled, an |
cancel
fun cancel(): Unit
Cancels this writer's caching operation. cache checks for cancelation frequently during execution, and throws an InterruptedIOException if it sees that the caching operation has been canceled.