# Context framework¶

Configuration options for TensorStore drivers are specified using a context framework, which allows resources such as cache pools, concurrent execution pools, and authentication credentials to be specified using JSON in a way that allows sharing of resources by multiple TensorStore drivers.

json Context : object

A context JSON object is a mapping of resource identifiers to ContextResource specifications.

Optional members

<resource-type> : ContextResource

Overrides the default resource for the given <resource-type>, which must be a supported resource type.

<resource-type>#<id> : ContextResource

Defines a resource with identifier <id> of the given <resource-type>. The resource specification must be compatible with <resource-type>.

Example

{
"cache_pool": {"total_bytes_limit": 10000000},
"cache_pool#remote": {"total_bytes_limit": 100000000},
"data_copy_concurrency": {"limit": 8}
}

json ContextResource : object | string | null

Specifies a context resource of a particular <resource-type>.

One of

object

Specifies the resource directly. All members are specific to the particular <resource-type>.

string

References another resource of the same type in the current or parent context using the syntax "<resource-type>" or "<resource-type>#<id>", where <resource-type> matches the type of this resource.

null

Specifies a new instance of the default resource of the given <resource-type>. Only valid within a Context specification.

json Context.cache_pool : object

Specifies the size of an in-memory Least Recently Used (LRU) cache. Each cache_pool resource specifies a separate memory pool.

Optional members

total_bytes_limit : integer[0, +∞) = 0

Soft limit on the total number of bytes in the cache. The least-recently used data that is not in use is evicted from the cache when this limit is reached.

queued_for_writeback_bytes_limit : integer[0, +∞)

Soft limit on the total number of bytes of data pending writeback. Writeback is initated on the least-recently used data that is pending writeback when this limit is reached. Defaults to half of total_bytes_limit.

json Context.data_copy_concurrency : object

Specifies a limit on the number of CPU cores used concurrently for data copying/encoding/decoding.

Optional members

limit : integer[1, +∞) | "shared" = "shared"

The maximum number of CPU cores that may be used. If the special value of "shared" is specified, a shared global limit equal to the number of CPU cores/threads available applies.

json Context.file_io_concurrency : object

Specifies a limit on the number of concurrently local filesystem I/O operations.

Optional members

limit : integer[1, +∞) | "shared" = "shared"

The maximum number of concurrent operations. If the special value of "shared" is specified, a shared global limit equal to the number of CPU cores/threads available (or 4 if there are fewer than 4 cores/threads available) applies.