CacheInterface

Optional external cache that tc-lib-pdf reuses across the sub-libraries that support caching (font subsets and processed images).

Namespace: Com\Tecnick\Pdf\Cache

File: CacheInterface.php line 56

Optional external cache that tc-lib-pdf reuses across the sub-libraries that support caching (font subsets and processed images).

A single implementation of this contract can be passed to the Tcpdf constructor and is internally adapted to each sub-library’s own cache interface, so the same backend (filesystem, APCu, Redis, a PSR-16 cache, …) serves every cacheable subsystem with one connection and one configuration.

No concrete implementation is shipped: the backend, its (de)serialization, expiration and size limits are the application’s responsibility. Implementations MUST be best-effort and MUST NOT throw on a miss or a transient backend failure.

Keys are already namespaced and schema-versioned by each sub-library (e.g. “tc-lib-pdf-font:subset:v2:…” and “tc-lib-pdf-image:v2:…”), so a single shared store is collision-safe.

Security: the cache store is a trust boundary. Cached values are embedded verbatim into generated PDFs, so anyone able to write to the backend can influence document output. Use a store only your application can write to, and when an implementation deserializes data it MUST disable object restoration (e.g. unserialize($s, [‘allowed_classes’ => false])).

Tags

Constants

TYPE_FONT

File: CacheInterface.php line 61

public mixed TYPE_FONT = 'font'

TYPE_IMAGE

File: CacheInterface.php line 66

public mixed TYPE_IMAGE = 'image'

Methods

get()

File: CacheInterface.php line 75

public get(string $key) : mixed

Parameters

  • $key : string: Cache key.

Return values

mixed —

Stored value, or null when absent.

set()

File: CacheInterface.php line 83

public set(string $key, mixed $value) : void

Parameters

  • $key : string: Cache key.
  • $value : mixed: Value to store.