Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #46699 [Cache] Respect $save option in all adapters (jrjohnson)
This PR was merged into the 4.4 branch. Discussion ---------- [Cache] Respect $save option in all adapters | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | I was working with a cache chain which included the array adapter. When we have a cache miss we need to consolidate all of the misses so we can do a single DB query for all values. So first we look in the cache, then and then we can pull the data as a big group, hydrate the results, and then cache them. Because we search for these values a bunch of times in the same request I chained the array and Redis adapter together. Looks like: ``` $hitsAndMisses = array_map( fn(mixed $id) => $this->cache->get($id, function (ItemInterface $item, bool &$save) { $save = false; return false; }), $ids ); $hits = array_filter($hitsAndMisses); //cut: compare arrays to get missed Ids $hydrated = $this->hydrate($missedIds); //very expensive to do individually $missedValues = array_map(fn($obj) => $this->cache->get( $obj->id, function (ItemInterface $item) use ($obj) { return $obj; } ), $hydrated); return array_values([...$hits, ...$missedValues]); ``` Unfortunately neither the `ArrayAdapter` nor the `ChainAdapter` respect the $save reference. I was able to fix the `ArrayAdapter` in this PR, but I'm at a loss for how to do the same for the `ChainAdapter`, but I was able to create a generic failing test. Commits ------- b14aa77 [Cache] Respect $save option in ChainAdapter 5e8de1e [Cache] Respect $save option in ArrayAdapter
- Loading branch information