Skip to content

refactor(cache): tighten TTL to interval-only, forbid bare-int minutes (task 2.2 / 3.6) - #42

Open
agissept wants to merge 1 commit into
migration/3.5-config-log-filesystemfrom
migration/3.6-cache-ttl-strict
Open

refactor(cache): tighten TTL to interval-only, forbid bare-int minutes (task 2.2 / 3.6)#42
agissept wants to merge 1 commit into
migration/3.5-config-log-filesystemfrom
migration/3.6-cache-ttl-strict

Conversation

@agissept

Copy link
Copy Markdown
Member

Stacked on migration/3.5-config-log-filesystem (retarget to dev-13 when the stack merges). Framework-first task 2.2 (fork side).

Why

L13 reads a bare-int cache TTL as seconds; the fork reads it as minutes. Once we swap to illuminate/cache v13 a bare int silently becomes 60× shorter. This makes the fork stricter than stock so the ambiguous form breaks loudly now and forces the app onto an absolute interval (Carbon::now()->addMinutes(N)), which is unit-safe on both fork and stock v13.

What

  • Repository::put/add/remember and TaggedCache::add/remember now require DateTimeInterface|DateInterval $ttl. getMinutes() tightened to an interval→minutes converter (fork stores stay minutes-based).
  • TaggedCache::put stays untyped — it implements StoreInterface::put (untyped), so narrowing the param is an LSP fatal. Its tightened getMinutes() still rejects bare int at runtime; add/remember (not in StoreInterface) are typed.
  • Converted the 4 fork-internal bare-int callers so the fork stays green: CacheBasedSessionHandler, Repository::offsetSet, Query\Builder::getCached, CachedRouting\Router (this last one's TypeError was swallowed by a best-effort catch(\Throwable) → routes silently uncached; only the full suite caught it).

Deliberately deferred (to task 2.3)

Relocate StoreInterfaceContracts\Cache\Store and implement Contracts\Cache\Repository. The contract's put($ttl = null) is looser, so the fork can't implement it while it's stricter (param-narrowing LSP). Kept getDefaultCacheTime/setDefaultCacheTime for now.

Enforcement note

This fork strictness evaporates on swap (stock v13 re-admits bare int). The permanent guard is a Psalm bare-int rule (task 0.3), not this type change.

Validation

Fork suite green (1642). App conform lives in a separate dicoding branch (improvement/l13-migration/cache-ttl-conform): unit 8088 green, cache integration 21 green, full integration back to the pre-existing baseline with 0 cache regressions.

🤖 Generated with Claude Code

…s (task 3.6)

Repository/TaggedCache put/add/remember now require DateTimeInterface|DateInterval.
Bare-int minutes (ambiguous minutes-vs-seconds — the silent 60x bug once swapped to
illuminate/cache v13, which reads int as seconds) is rejected. App must pass
Carbon::now()->addMinutes(N), unit-safe on both fork and stock v13.

- TaggedCache::put stays untyped (StoreInterface::put is untyped -> narrowing = LSP
  fatal) but getMinutes tightened rejects bare int at runtime; add/remember typed.
- Convert 4 fork-internal bare-int callers to intervals: CacheBasedSessionHandler,
  Repository::offsetSet, Query\Builder::getCached, CachedRouting\Router.
- Deferred to task 2.3: relocate StoreInterface -> Contracts\Cache\Store + implement
  Contracts\Cache\Repository (contract's put($ttl=null) is looser -> can't implement
  while stricter).

Framework-first task 2.2 (fork side). Permanent guard (Psalm bare-int rule) and app
conform are follow-ons. Fork suite green (1642).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant