feat: add carbon support for cache expiry #10
Closed
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.
This pull request adds
nesbot/carbon
support for determining the cache TTL.I'm used to use
now()->addHour()
for the TTL on Laravel's caching utilities, so it was a bummer when migrating some code to Saloon to see it doesn't support this.To achieve support for this feature without breaking change, the
Cacheable
interface has been changed to removecacheExpiryInSeconds
. Instead, theHasCaching
trait usesmethod_exists
to find either the deprecatedcacheExpiryInSeconds
or the newcacheExpiry
method.The new
cacheExpiry
can either return anint
or aCarbonInterface
. In either case, the cache expiry will be resolved to seconds internally to minimize changes to the codebase.Note that I have other concerns with the DX, as stated in https://github.com/Sammyjo20/saloon-cache-plugin/issues/11, so maybe it's worth not accepting this PR and make a bigger refactor for a better Laravel integration