@UnstableApi
class CacheWriter


Caching related utility methods.

Summary

Nested types

Receives progress updates during cache operations.

Constants

const Int

Default buffer size to be used while caching.

Public constructors

CacheWriter(
    dataSource: CacheDataSource!,
    dataSpec: DataSpec!,
    temporaryBuffer: ByteArray?,
    progressListener: CacheWriter.ProgressListener?
)

Public functions

Unit

Caches the requested data, skipping any that's already cached.

Unit

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 CacheDataSource that writes to the target cache.

dataSpec: DataSpec!

Defines the data to be written.

temporaryBuffer: ByteArray?

A temporary buffer to be used during caching, or null if the writer should instantiate its own internal temporary buffer.

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 InterruptedIOException is thrown. The method may be called again to continue the operation from where the error occurred.

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.