Skip to content

implement context caching#135

Merged
Plytas merged 15 commits into
google-gemini-php:mainfrom
michabbb:codex/implement-context-caching-in-php-sdk
Sep 12, 2025
Merged

implement context caching#135
Plytas merged 15 commits into
google-gemini-php:mainfrom
michabbb:codex/implement-context-caching-in-php-sdk

Conversation

@michabbb

Copy link
Copy Markdown
Contributor

Summary

  • implement cached content resource and data handling
  • expose cachedContent methods on client & client fake
  • add model enum patch
  • provide tests and fixtures for cached content

Testing

  • composer lint
  • vendor/bin/phpstan analyse --ansi
  • vendor/bin/pest --colors=always

Summary by CodeRabbit

  • New Features
    • Introduced comprehensive cached content management: create, retrieve, list, update, and delete cached contents via the client interface.
    • Added detailed metadata and list responses for cached content, improving data handling and visibility.
    • Enhanced HTTP support by adding the PATCH method for partial updates.
  • Tests
    • Delivered extensive unit tests covering all cached content operations and response behaviors for robustness and accuracy.

michabbb and others added 14 commits July 16, 2025 23:56
…412023

Add claude GitHub actions 1752708412023
- Add name parameter validation (empty string and invalid characters)
- Add TTL format validation for duration format (e.g., "60s", "120.5s")
- Follow same validation pattern as DeleteRequest for consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add @PHPStan-Ignore nullCoalesce.offset for promptTokenCount field.

The Gemini API documentation specifies that promptTokenCount is required,
but in practice the API sometimes returns responses without this field
(particularly for cached content operations). This causes runtime errors
when the field is missing.

The ?? 0 fallback handles the real-world API behavior, while the PHPStan
ignore comment suppresses the static analysis warning that claims the
offset always exists (which contradicts actual API responses).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace @PHPStan-Ignore with proper type definition that reflects real API behavior.
Changed promptTokenCount from required (int) to optional (?int) in the DocBlock.

Cache creation operations may not involve LLM interactions, resulting in incomplete
usage metadata where promptTokenCount and other fields can be missing from the API response.

This fix resolves PHPStan warnings across all PHP versions (8.1-8.4) while maintaining
the existing runtime fallback behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@michabbb

Copy link
Copy Markdown
Contributor Author

everything has been tested with this script: https://gist.github.com/michabbb/577b4cb65273bed7e0e6ddde10268f6a

@michabbb michabbb mentioned this pull request Jul 17, 2025
@Plytas
Plytas merged commit c90c43a into google-gemini-php:main Sep 12, 2025
10 checks passed
@Plytas

Plytas commented Sep 12, 2025

Copy link
Copy Markdown
Collaborator

Thanks for this @michabbb!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants