Spoc_framework_registry.Framework_cachetype stats = {mutable hits : int;Successful cache lookups
*)mutable misses : int;Failed cache lookups
*)mutable puts : int;Cache writes
*)mutable errors : int;I/O errors
*)}Cache statistics
val stats : statsval get_stats : unit -> statsGet current cache statistics
The directory entries may be read from and written to, or None when it cannot be trusted. Cached OpenCL entries are native device binaries that a driver loads, so a directory another user can write to would let them substitute code. Refused (one warning per process): no XDG_CACHE_HOME and no HOME (the only fallback is the shared temporary directory), a directory not owned by the current user, and a directory writable by group or others. A directory this module creates is mode 0o700.
On-disk key schema version. Bump this whenever the key inputs change so stale entries written under an older schema can never mis-hit - they simply become unreachable orphans (safe: just re-computed and rewritten under the new key). v2 adds the kernel/entry name to the digest (v1 keys omitted it, so two kernels sharing one source string collided).
val compute_key_with_options :
options:(string * string) list ->
dev_name:string ->
driver_version:string ->
name:string ->
source:string ->
stringCompute cache key from device, driver, kernel/entry name, and source.
name (the kernel/entry-point name) must be included: a single source string may define more than one kernel, and without the name in the key a second kernel compiled from the same source would return the first kernel's cached SPIR-V. The device identity is deliberately the device NAME + driver version (not an enumeration-order ordinal) so the key stays stable across process restarts where device enumeration order is not guaranteed.
Delegates to Compile_cache.make_key for the name/source component so this on-disk cache uses the same collision-resistant, digest-per-field join as every backend's in-memory compile cache. dev_name and driver_version are digested independently before being combined into the single device component make_key expects, so a value containing ':' in either field can never shift bytes between them (the same class of bug key_schema_version concatenation used to have). The key_schema_version prefix is preserved as an outer wrapper around the digest so schema bumps still invalidate stale on-disk entries.
This is compute_key for a backend whose binary also depends on a build-option string (OpenCL): options is forwarded to Compile_cache.make_key, so a different option set can never hit an entry built under another.
val compute_key :
dev_name:string ->
driver_version:string ->
name:string ->
source:string ->
stringcompute_key_with_options for a backend with no build options.
Retrieve cached data by key; None when absent, when the cache is disabled (see enabled) or when its directory is not trusted (see trusted_dir).
Write data to a fresh temporary file in dir and rename it onto filename. The temporary name is unique per call (Filename.temp_file: exclusive creation, random suffix), so concurrent writers (threads, domains or processes) never share a file; the rename is atomic on a POSIX filesystem, so a reader opening filename sees one complete entry, either the previous one or a new one.
Store data in cache with given key; see write_atomically for what a concurrent get can observe. No-op when the cache is disabled (see enabled) or its directory is not trusted (see trusted_dir).