1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\Schema\Result;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Enum\CacheScope;
18: use Nexus\Mcp\Core\Schema\MetaObject\GenericResultMetaObject;
19: use Nexus\Mcp\Core\Schema\MetaObject\ResultMetaObject;
20: use Nexus\Mcp\Core\Schema\Result;
21:
22: /**
23: * A result that supports a time-to-live (TTL) hint for client-side caching.
24: *
25: * @template-covariant T of array<string, mixed>
26: *
27: * @extends Result<T>
28: *
29: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2026-07-28/schema.ts
30: */
31: abstract readonly class CacheableResult extends Result
32: {
33: public function __construct(
34: public int $ttlMs,
35: public CacheScope $cacheScope,
36: ResultMetaObject $meta = new GenericResultMetaObject(),
37: ) {
38: Assert::that($this->ttlMs)->isNaturalInt('"result.ttlMs" must be a non-negative integer, {value} given.');
39:
40: parent::__construct(meta: $meta);
41: }
42: }
43: