Repository navigation
Add memo interop, tag flush parity, and versioned chunks (1.16.0) - #58
Merged
Merged
Conversation
- tags(...)->flush() flushes only those tags, like Laravel's Cache::tags()->flush(); a plain flush() still clears the store. - Opt-in smart-cache.memo.native builds memo() on Laravel's Cache::memo() (12.9+); bookkeeping is never memoized in either mode. - Chunked writes use versioned chunk keys and delete the replaced entry's chunks once the new entry is stored; rejected chunk writes fall back; forever chunks are registered for cleanup-chunks. - Laravel 13 Repository parity: enum keys, typed getters, missing(), rememberWithWarmth(), Closure TTLs, variadic tags, flexible() DateInterval durations, tagged putMany() tags every key. - Deferred 1.15 fixes: Redis SCAN prefixes, chunk registry, lazy chunk partial data, managed-key index lost updates. - Disabled strategies still decode their entries; namespaced pattern and model invalidation; original-value placeholders; queue worker state refresh; KeyWritten tags; circuit breaker and XFetch fixes.
- Follow up to three replacements when a chunked entry's chunks are gone, and evict only an entry that is still stored and broken. - tags([])->flush() removes nothing; empty many()/getMultiple()/ deleteMultiple() calls count as cache calls for a later flush(). - Merge chunk-registry entries so a concurrent forever() write that lost keeps its chunks registered; log when the registry cannot be stored. - Re-assert rewritten keys in the managed-key index at the next persist. - Native memo: keys added or read past the memo layer are read from the store for the rest of the request; locks come from the store below the memo layer. - Document the pending-tags flush caveat and the rolling-deploy effect on 1.15 readers.
- Skip the chunk registry entirely for writes that add or delete no chunks; every put() had started reading it. - Self-healing evicts the entry right after the read that confirms it is broken, before the slower chunk and registry cleanup. - flexible() and getRaw() read keys added past a native memo layer from the store, as get() and has() do. - Note that Laravel's own Cache::memo() keeps its earlier miss after a SmartCache add(); update test counts.
The dependency map stored keys without the namespace, so tenants using the same key names shared one edge: one tenant's invalidate() consumed it and another tenant's dependent key stayed stale. Under a namespace, dependsOn() now also stores the edge with the namespace on both ends, and invalidate() follows that copy first. The un-namespaced edge is still written and followed exactly as before, so 1.15 servers keep invalidating during a rolling deploy and dependencies declared before the upgrade keep working. Without a namespace nothing changes.
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.
This is release 1.16.0. It answers three community requests (tag-driven flushing of chunked data,
Cache::memo()interoperability, and "smart-tagging" of chunks), aligns SmartCache with Laravel 13.33/13.34, and ships the four fixes deferred from 1.15.SmartCachecontract is unchanged.memo.native, defaultfalse.Tests:
vendor/bin/phpunitreports 678 passing (605 before, 2 pre-existing skips). I also ran the suite locally on Laravel 12.70, 11.57, 10.50 and 9.x; the native-memo tests skip before 12.9, as expected.There are 71 new tests in
tests/Unit/V116FeaturesTest.php, plus 2 inEnumeratesCacheKeysTest. Of the 71, 54 fail on 1.15.0. The other 17 are labelled guards. They pin behavior that must not change, cover the opt-in native memo mode (which 1.15 does not have), or protect against a race or cost the new chunk, registry, index, and dependency handling could introduce. 16 of the guards pass on 1.15; the 17th fails there only because it uses the new registry constant.Community requests
1.
tags()/ tag contractSmartCache already had
tags()andflushTags(), andflushTags()already deleted chunk keys,_sc_metaand_sc_dna. The real gap wasSmartCache::tags('reports')->flush(): it wiped the entire store, while Laravel'sCache::tags()->flush()clears only the tag. Docs before 1.15 showed that call as the way to clear tagged entries.tags(...)->flush()now clears only those tags (your call). A plainflush(), or aflush()after any other cache call, still clears the store.tags([])->flush()removes nothing.tags('a', 'b')works like Laravel (previouslybwas dropped), and enum tag names are accepted.supportsTags()istrue, since SmartCache's own tag index works on every store.tags('t')->putMany([...])tagged only the first key, soflushTags('t')left the others stale.2.
Cache::memo()interop (opt-in, your call)smart-cache.memo.native = true(Laravel 12.9+) buildsSmartCache::memo()on Laravel'sCache::memo(). There is one memo layer per store, shared withCache::memo()and every othermemo()call, and Laravel clears it between requests and jobs. SmartCache still compresses, chunks and restores above it.Edge cases handled:
add()stays atomic. Laravel's memoized store has noadd(), so the write goes to the store, and SmartCache reads that key from the store for the rest of the request.rememberWithLock()reads a value another process stored.drivers.*settings come from the store below the memo layer.Separately,
memo()fixes that apply in both modes:memo()->put()skip a needed write and report success, and tag-index updates dropped other processes' entries.memo()->flush()now clears the memo layer.3. Chunk lifecycle (versioned chunks, your call)
_sc_chunk_{key}_{version}_{index}). The replaced entry's chunks are deleted only after the new entry is stored. Previously chunks were rewritten in place, so a concurrent reader could get rows from both versions without any error.forever()keys).put()returns true. The value falls back to compression.put()with a TTL ≤ 0 deletes the chunks too.Deferred 1.15 findings (all included, your call)
smart-cache:clear --forcedeletes keys on Redis for the first time; see the upgrade note.cleanupOrphanChunks()also removes registered chunks the current entry no longer uses, and runs under a metadata lock. Plain writes never read the registry.flexible()'s stale path loads it before refreshing, andmaterialize()is new.clearManaged()starts from the stored index.Other fixes from the audit
string()/integer()/float()/boolean()/array(),missing()andrememberWithWarmth(). These fell through to the raw repository and returned the internal wrapper on optimized keys.DateIntervaldurations inflexible().rememberForever()).flushPatterns(),invalidateModel()and model patterns now also match the namespace's keys.save()._sc_dependencies, so one tenant'sinvalidate()consumed it and another tenant's dependent key went stale.dependsOn()now also stores a namespaced copy of the edge, andinvalidate()follows that copy first.Loopingevent, keeping the namespace. A refresh job queued without a namespace no longer runs in a namespace leaked by an earlier job.KeyWritten: it carries the write's tags, and fires forforever(),add()andflexible().Upgrade notes (also in CHANGELOG)
tags(...)->flush()now clears only those tags. Because the facade is one shared instance, atags()call left unused (for example, when computing the value throws) also makes a laterflush()in the same request tag-only. That is the same pending-tags behavior that has always tagged the next write.smart-cache:clear --forceon Redis now deletes every non-SmartCache key of that cache store. That is roughlycache:clearfor the store. Shared keys such asilluminate:queue:restartare included.In the same race, a 1.15-only fleet silently mixed rows.
Reviews
Three audit agents (strategies, services and commands, Repository parity) produced the fix list.
Codex found 8 issues; 7 are fixed with tests, and initial commit with package scaffold #1 (1.15 readers during a rolling deploy) is documented as an upgrade note:
tags([])->flush()wiped the store;add()was invisible to the memo layer;flush()tag-only;Its 8th point is kept as designed and stated in the CHANGELOG: after a lock timeout the update runs without the lock, which is the existing best-effort locking.
Fable, two passes. It confirmed the four decisions are implemented. Fixed with tests:
rememberWithLock(), the memo layer kept the earlier miss;Documented: the pending-tags flush caveat and the rolling-deploy details.
Not in this PR (need a decision)
reset()does not restorewithJitter()/withCircuitBreaker()toggles. Restoring them would break apps that set them once at boot in Octane.GET /and/healthrunhealthCheck(), which prunes expired index entries and broken chunked entries. They are safe deletions, but they happen on GET.Docs
docs/index.html, CHANGELOG (1.16.0), SECURITY.md (maintained line → 1.16.x), config comments, and test counts.memo()returns aMemoizedCacheDriver;🤖 Generated with Claude Code