Fluent configuration API and object-argument cache keys - #11
Merged
Merged
Conversation
Replace the void setTtl()/setEnabled() setters with a chainable, Laravel-style grammar (ttl/enable/disable/prefix/withTags/tagCleaners/ exclude, all returning static) and support objects as method arguments via a new overridable normalizeArgument() seam. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two Otwell-flavored improvements to the public surface of
CacheDecorator:1. Fluent, chainable configuration API
voidsetterssetTtl()/setEnabled(bool).static:ttl($ttl)— TTL in seconds /DateInterval/DateTimeInterface/nullto bypassenable()/disable()— toggle caching readablyprefix(?string),withTags(array),tagCleaners(array),exclude(string ...)initExcludes()defaults so__call()resolves it on the decorator instead of forwarding to the inner object.2. Object arguments in cache keys
Resolves the long-standing
@todo/ "coming in v1.0.0" caveat. Arguments may now be scalars, arrays, or objects, folded into the key through a new overridablenormalizeArgument(mixed): stringseam:UrlRoutable—getRouteKey()BackedEnum—->value;Stringable/__toString— string castjson_encode, falling back tomd5(serialize(...))Subclasses can override
normalizeArgument()to customize identity.Why
The previous surface read like a 2015-era package:
voidsetters that don't chain, and unsupported object arguments. These changes make configuration expressive and self-documenting and let models/enums/value objects be passed as cached method arguments.Notes
setTtl()/setEnabled()are removed (the package isn't in production use yet). Migration is documented in the README upgrade notes.Tests
Full suite green (40 tests / 66 assertions),
pint --testpasses,phpstan(larastan) clean. New tests cover the fluent setters returning the decorator,enable()/disable()/ttl()behavior, chained-call resolution (regression guard on the exclude-list), and object-argument keying by identity.🤖 Generated with Claude Code