@UnstableApi
class CacheDataSink : DataSink


Writes data into a cache.

If the DataSpec passed to open has the length field set to LENGTH_UNSET and FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN set, then write calls are ignored.

Summary

Nested types

Thrown when an IOException is encountered when writing data to the sink.

DataSink.Factory for CacheDataSink instances.

Constants

const Int

Default buffer size in bytes.

const Long

Default fragmentSize recommended for caching use cases.

Public constructors

CacheDataSink(cache: Cache!, fragmentSize: Long)

Constructs an instance using DEFAULT_BUFFER_SIZE.

CacheDataSink(cache: Cache!, fragmentSize: Long, bufferSize: Int)

Public functions

Unit

Closes the sink.

Unit
open(dataSpec: DataSpec!)

Opens the sink to consume the specified data.

Unit
write(buffer: ByteArray!, offset: Int, length: Int)

Consumes the provided data.

Constants

DEFAULT_BUFFER_SIZE

const val DEFAULT_BUFFER_SIZE = 20480: Int

Default buffer size in bytes.

DEFAULT_FRAGMENT_SIZE

const val DEFAULT_FRAGMENT_SIZE = 5242880: Long

Default fragmentSize recommended for caching use cases.

Public constructors

CacheDataSink

CacheDataSink(cache: Cache!, fragmentSize: Long)

Constructs an instance using DEFAULT_BUFFER_SIZE.

Parameters
cache: Cache!

The cache into which data should be written.

fragmentSize: Long

For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set to LENGTH_UNSET then no fragmentation will occur. Using a small value allows for finer-grained cache eviction policies, at the cost of increased overhead both on the cache implementation and the file system. Values under (2 * 1024 * 1024) are not recommended.

CacheDataSink

CacheDataSink(cache: Cache!, fragmentSize: Long, bufferSize: Int)
Parameters
cache: Cache!

The cache into which data should be written.

fragmentSize: Long

For requests that should be fragmented into multiple cache files, this is the maximum size of a cache file in bytes. If set to LENGTH_UNSET then no fragmentation will occur. Using a small value allows for finer-grained cache eviction policies, at the cost of increased overhead both on the cache implementation and the file system. Values under (2 * 1024 * 1024) are not recommended.

bufferSize: Int

The buffer size in bytes for writing to a cache file. A zero or negative value disables buffering.

Public functions

close

fun close(): Unit

Closes the sink.

Note: This method must be called even if the corresponding call to open threw an IOException. See open for more details.

open

fun open(dataSpec: DataSpec!): Unit

Opens the sink to consume the specified data.

Note: If an IOException is thrown, callers must still call close to ensure that any partial effects of the invocation are cleaned up.

Parameters
dataSpec: DataSpec!

Defines the data to be consumed.

write

fun write(buffer: ByteArray!, offset: Int, length: Int): Unit

Consumes the provided data.

Parameters
buffer: ByteArray!

The buffer from which data should be consumed.

offset: Int

The offset of the data to consume in buffer.

length: Int

The length of the data to consume, in bytes.